- Here I'm trying to send the compressed report to an email. The code below was put inside program.cs at the end before return error;
Can somebody help me with this?
we use office365 here, so should I use smtp.office365.com or smtp.mycompany.com??
During debug too didn't find any error. everything was in place.
Thanks in advance
*BEGINNER
Code: Select all
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
mail.Subject = "Test Results";
SmtpClient SmtpServer = new SmtpClient("smtp.mycompany.com");
SmtpServer.Port = 25;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Timeout = 5000;
String zipFileName = Ranorex.Core.Reporting.TestReport.ReportEnvironment.ReportZipFilePath;
if (System.IO.File.Exists(zipFileName))
{
System.Net.Mail.Attachment MyReport = new System.Net.Mail.Attachment(zipFileName);
mail.Attachments.Add (MyReport);
}
SmtpServer.Send(mail ); //--------If I use SendAsync(mail, mail), It does pass the test but doesn't send an email.
// This is where the error message is pointed out.
Report.Info("Email sent");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Report.Error(ex.StackTrace);
}
at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)