Canarys | IT Services



Wouldn’t it be great if Test Report are sent automatically across team as soon the Test Execution is complete??

Now, let’s see how to achieve this using Office, and account as the SMTP host.

Include the below code in your OneTImeTearDown (NUnit) or AfterClass (TestNG) method: we attain this feature using library => System.Net.Mail;


using System.Net.Mail;

namespace MailConfiguration


            static void Main(string[] args)


                        string _sender = “”;

                        string _password = “your password”;

            string _recipient = “”;

                        string subject = “Test Mail”;

                        string message = “Hello!!”;

                        //Outlook SMTP client configuration

                        SmtpClient client = new SmtpClient(“”);


                        //Gmail SMTP client configuration

                        //SmtpClient client = new SmtpClient(“”);

                        //SMTP server uses port è 25, 587(recommended)

                        client.Port = 587;


                        //Authorize connection

                        client.DeliveryMethod = SmtpDeliveryMethod.Network;

                        client.UseDefaultCredentials = false;

                        System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(_sender, _password);

                        client.EnableSsl = true;

                        client.Credentials = credentials;


                        //Send Mail



                                    var mail = new MailMessage(_sender.Trim(), recipient.Trim());

                                    mail.Subject = subject;

                                    mail.Body = message;


                                    //Remote Certificate Authentication

                                    ServicePointManager.ServerCertificateValidationCallback =

                                                 delegate (object s, X509Certificate certificate,

                                     X509Chain chain, SslPolicyErrors sslPolicyErrors)

                                                 { return true; };


                                     //Add Attachment/s

                                     System.Net.Mail.Attachment attachment;

                                     attachment = new System.Net.Mail.Attachment(@”Attachment  Location”);



                                    //Send Mail




                          catch (Exception ex)



                                    throw ex;





Please do subscribe to our blogs & keep yourself updated with new posts.

Happy Reporting smiley

Happy Testing smiley


Leave a Reply

Your email address will not be published. Required fields are marked *

Reach Us

With Canarys,
Let’s Plan. Grow. Strive. Succeed.