Sending Test Results via E-Mail

In some software test automation scenarios you may want the test harness to programmatically send test results via e-mail in addition to, or instead of, saving results to a file or database. In a .NET environment, this is pretty easy to do. The first step is to configure the test host machine, which is running the test automation, as an SMTP server so the host can send mail. On Windows XP, if you have configured IIS, in most cases SMTP will also be enabled, but not configured. In Computer Management, under IIS, open the SMTP Virtual Server Properties dialog. On the General tab, enter the IP address of the host machine. Port 25 will be the default. Then on the Access tab, Connection section, add the IP address of the test host machine. Now your test host can send mail. You can use the older System.Web.Mail namespace, or the newer System.Net.Mail namespace. C# code to send mail this looks like:
using System.Net.Mail;
  SmtpClient c = new SmtpClient("", 25); // host IP, port
  MailAddress mFrom = new MailAddress("results@testHost");
  MailAddress mTo = new MailAddress("");
  MailMessage m = new MailMessage(mFrom, mTo);
  m.Subject = "Test Results at" + System.DateTime.Now;
  string mBody = "Number Pass = 120\nNumber Fail = 0";
  m.Body = mBody;
If your test host machine is not running under a .NET environment, you can use the old CDONTS or the newer CDOSYS ActiveX libraries.
This entry was posted in Software Test Automation. Bookmark the permalink.