Automation SMTP Server

Posted on by

About

Automation SMTP Server is simple SMTP server run as console application. It acts as SMTP server saving all email messages as EML file to disk. With build in EMLFile class you can later read those emails and verify them in your automation testing project.

More info can be found in Complete guide to email verifications with Automation SMTP Server post.

Download

SMTP server can be found as EXE with its CONFIG file in GitHub releases.

Configuration

  • Port – Automation SMTP Server have a config file in which port on which server listens can be configured. Port also can be passed as argument when running it from command prompt. It port is not provided in one of both ways 25 is taken by default.
  • Emails directory – emails are saved in folder named “temp” in same directory where Automation SMTP Server EXE is. This cannot be changed.

Usage

1. From your automation test project add reference to AutomationSMTPServer.exe.
2. Delete previous emails

private string currentDir =
	Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar;
private string mailsDir = currentDir + "temp";

if (Directory.Exists(mailsDir))
{
	Directory.Delete(mailsDir, true);
}

3. Start Automation SMTP Server as process

Process smtpServer = new Process();
smtpServer.StartInfo.FileName = currentDir + "AutomationSMTPServer.exe";
smtpServer.StartInfo.Arguments = "25";
smtpServer.Start();

4. Read emails

string[] files = Directory.GetFiles(mailsDir);
List<EMLFile> mails = new List<EMLFile>();

foreach (string file in files)
{
	EMLFile mail = new EMLFile(file);
	mails.Add(mail);
	File.Delete(file);
}

5. Do desired verifications with EMLFile objects
6. Stop Automation SMTP Server by killing the process

smtpServer.Kill();
If you find this post useful, please share it to reach more people. Sharing is caring!
Share on FacebookShare on LinkedInTweet about this on TwitterShare on Google+Email this to someone