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 365.com, Outlook.com and Gmail.com 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 = "youraccount@outlook.com";

                        string _password = "your password";

            string _recipient = "RecipientId@domain.com";

                        string subject = "Test Mail";

                        string message = "Hello!!";

                        //Outlook SMTP client configuration

                        SmtpClient client = new SmtpClient("smtp.office365.com");

 

                        //Gmail SMTP client configuration

                        //SmtpClient client = new SmtpClient("smtp.gmail.com");

                        //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

                        try

                        {

                                    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");

                                     mail.Attachments.Add(attachment);

                                   

                                    //Send Mail

                                    client.Send(mail);

                           }

 

                          catch (Exception ex)

                          {

                                    Console.WriteLine(ex.Message);

                                    throw ex;

                          }

             }

     }

 

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

Happy Reporting smiley

Happy Testing smiley

 

Related

What is Defect? Defect Life Cycle in Software Testing.

Defect is an unexpected behavior of the software application flow against the requirement specificat...

Read More >

What are Frames? How to handle frames in Selenium WebDriver with C#?

IFrame (FullForm: Inline Frame) is an HTML document that is included in another HTML document and is...

Read More >

What is Synchronization? Handling Synchronization in Selenium WebDriver using C#:

Synchronization meaning: when two or more components involved to perform any action, we expect these...

Read More >

Extent Reports in Selenium CSharp (C#)

Reports play a fundamental role when it comes to TESTING. Tester can now  know the real-time r...

Read More >

Assertions in Coded UI

Let us discuss how to add assertions in coded UI. Assertions are checkpoints/benchmarks to UI c...

Read More >

Analysis of Load Test Results

Analysis of Performance DataAfter you capture and consolidate your results, analyze the captured dat...

Read More >

Parallel Execution using Selenium Webdriver and TestNG

While testing a web application it is very important to test the application on different browsers. ...

Read More >

ASP.NET: Audit Trail Implementation using Entity Framework

When you are working with certain projects which involves the Customer records, you might need to tr...

Read More >

Create Restful service using Web API

What is Asp.Net Web API?Asp.Net Web API is a framework for building HTTP services that can be consum...

Read More >

Share

Post a Comment

  • Recent
  • Popular
  • Tag
Monthly Archive
Subscribe
Name

Contact Us
  • *
  • *