Sending emails is I guess a quite common feature in business applications development, so there’s a common necessity to apply to send emails tests. In my opinion, apart from unit testing, it is good practice to validate if email as the end product of specific application behaviour was sent and if has proper recipients, subject or message.

There is a couple of tools for email testing such as:

With full respect to this tool, I prefer a simple yet powerful method to do this job.

 var smtpClient = new SmtpClient
                DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory,
                PickupDirectoryLocation = @"C:\EmailBox"

            var mailMessage = new MailMessage();
            mailMessage.From = new MailAddress("");
            mailMessage.Subject = "Our subject";
            mailMessage.Body = "Our body";


You can view this file in your default email client.

MIME-Version: 1.0
Date: 23 Oct 2018 19:10:35 +0200
Subject: Our subject
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable

Our body

You can parse this file manually, but maybe a better option is to use a dedicated tool, like this.

PM> Install-Package MimeKitLite 

You can easily get email data from a file and validate it in integration tests.

   var lastSavedFilePath = new DirectoryInfo(@"C:\EmailBox").GetFiles().OrderByDescending(f => f.LastWriteTime).FirstOrDefault()?.FullName;
            var mimeMessage = MimeMessage.Load(lastSavedFilePath);

            var mailto = mimeMessage.To;
            var mailfrom = mimeMessage.From;
            var mailcc = mimeMessage.Cc;
            var mailsubject = mimeMessage.Subject;
            var maildate = mimeMessage.Date;
            var mailplainBody = mimeMessage.TextBody;
            var mailhtmlBody = mimeMessage.HtmlBody;

SmptClient can be also configured in app.config or web.config file.
Here’s snippet for this, but I wouldn’t follow this approach.

      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <specifiedPickupDirectory pickupDirectoryLocation="C:\yourEmailDirectory" />