Page 1 of 3

Send Mail Module

Posted: Thu Jun 30, 2011 12:42 pm
by Support Team
Use this module at any position within your test suite to get informed about test runs by email. This is especially useful for overnight test executions on runtime machines.

Usage:
  1. Download the "SendMail.cs" file to your computer and import it into your project by right-clicking your project in Ranorex Studio and choose "Add" -> "Existing Item..."
  2. Drag & Drop the module to your test case and define the variables by binding them to a parameter in your test case

    Variables:
    To (required)
    The email address of the message recipient.

    From (required)
    The email address of the message sender.

    ServerHostname (required)
    The hostname of the mail server.

    ServerPort
    The port of the mail server. Default is 25.

    Subject
    The subject of the message.

    Message
    The description of the message.

Re: Send Mail Module

Posted: Fri Aug 26, 2011 1:59 pm
by omayer
How to send .rxlog file as attachement.
Thanks,
Beginner

Re: Send Mail Module

Posted: Mon Aug 29, 2011 8:38 am
by Support Team
Hi,

Therefore please take a look to this link
http://csharp.net-informations.com/comm ... chment.htm
I justed used Google to find this info.

Regards,
Peter
Ranorex Team

Re: Send Mail Module

Posted: Mon Aug 29, 2011 1:31 pm
by omayer
Thank you Peter, It's worked
Beginner

Re: Send Mail Module

Posted: Thu Dec 22, 2011 11:44 am
by Support Team
If your server requires basic authentication (instead of using the standard Windows authentication), i.e. a user name and password, just edit following part in the the SendMail method of the module:
SmtpClient smtp = new SmtpClient(ServerHostname, int.Parse(ServerPort));
smtp.Credentials = new System.Net.NetworkCredential("userName", "password");
smtp.Send(mail);
Regards,
Alex
Ranorex Team

Re: Send Mail Module

Posted: Wed May 15, 2013 5:41 pm
by omayer
How to attach latest report w/out hard coded the attachment file, thank you in advance

System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("TestSuite_20130515_114627.html");
mail.Attachments.Add(attachment);

Re: Send Mail Module

Posted: Thu May 16, 2013 8:30 am
by odklizec
Hi, try this...
using Ranorex.Core.Reporting;

string RepName = TestReport.ReportEnvironment.ReportName;   
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(RepName + ".html");
mail.Attachments.Add(attachment);

Re: Send Mail Module

Posted: Thu May 16, 2013 3:52 pm
by Support Team
Hello,

You might need to attach the data file since it is used to store information.
You could achieve to include a compressed report file (rxzlog) in your mail by using the following code snippet:
// get the zipped report file path
String zipFileName = Ranorex.Core.Reporting.TestReport.ReportEnvironment.ReportZipFilePath;

// adds the zipped report to the mail
if (System.IO.File.Exists(zipFileName))
{
	System.Net.Mail.Attachment MyReport = new System.Net.Mail.Attachment(zipFileName);
	mail.Attachments.Add (MyReport);
}
Please don't forget to enable 'Compressed Copy' of your report in the Test Suite settings.

Regards,
Markus (T)

Re: Send Mail Module

Posted: Thu May 16, 2013 6:09 pm
by omayer
Thank you Markus, Not getting any attachment only mail body shows 'TestResult'

Code: Select all

  // get the zipped report file path   
				MailMessage mail = new MailMessage(From, To, Subject, Message);
                             
               String zipFileName = Ranorex.Core.Reporting.TestReport.ReportEnvironment.ReportZipFilePath;

				// adds th[attachment=0]ReportSetting.png[/attachment]e zipped report to the mail   
				if (System.IO.File.Exists(zipFileName))   
				{   
				    System.Net.Mail.Attachment MyReport = new System.Net.Mail.Attachment(zipFileName);   
				    mail.Attachments.Add (MyReport);   
				}  

                SmtpClient smtp = new SmtpClient(ServerHostName, int.Parse(ServerPort));
                smtp.Send(mail);

                
                Report.Success("Email has been sent to '" + To + "'.");
            }

Re: Send Mail Module

Posted: Fri May 17, 2013 8:13 am
by odklizec
Did you debug your send mail code? Does the rxzlog file exists at a time you call the send mail code? The thing is, that the "rxzlog" file is created after everything else is done. So make sure your send mail code is placed as the very last step in your test. The best place is probably Program.cs, just before return error; line. Hope this helps? ;)

Re: Send Mail Module

Posted: Tue Jun 18, 2013 3:07 pm
by Andrew.J.Ebert
In the direction is says "define the variables by binding them to a parameter in your test case." What do you mean by this? I am fairly unfamiliar with Ranorex and C# so I am completely lost trying to add this automatic report email. Any help or more detailed instructions greatly appreciated!

Re: Send Mail Module

Posted: Wed Jun 19, 2013 2:25 pm
by Support Team
Hello Andrew,

I would recommend to take a look at our User Guide.
The chapter Data-Driven Testing describes how you could use variables and parameters.
Additionally, our screencast provides a good overview.

We plan to implement an easier way to send reports via email in one of our next versions.

Regards,
Markus (T)

Re: Send Mail Module

Posted: Wed Aug 14, 2013 3:43 pm
by Andrew.J.Ebert
I have the Sendmail.cs script located at the end of my test suite. However I keep getting an error that it cannot find the specified report file. I enabled the compressed copy of the report and am attaching the correct file.

I think this is because the report isn't generated until after Sendmail tries to execute. Is this correct? If so, were should it be placed in my test suite?

Re: Send Mail Module

Posted: Wed Aug 14, 2013 3:48 pm
by odklizec
Hi Andrew,

Yes, you need to call the SendMail as the very last step in your test suite (after creating the report file). I think the best place is Program.cs, just before the final return error; line.

See my post here:
http://www.ranorex.com/forum/send-mail- ... tml#p19797

Re: Send Mail Module

Posted: Wed Aug 14, 2013 3:54 pm
by Andrew.J.Ebert
Sorry I should read before I post.

I am pretty much C# illiterate so please bare with me on this. How would I call Sendmail.cs? Can you give me a code example by chance?