Testing SMTP with .net

Solution 1:

There's also Papercut which is an SMTP server which will receive messages but not deliver them anywhere (allowing you to make sure they are being sent correctly). The received messages are visible in a small GUI and are also written to a directory.

Solution 2:

In .NET, SmtpClient can be configured to send email by placing it in a pickup directory.

The default constructor of SmtpClient takes its settings from app.config, so for a test environment we can configure it as follows.

<configuration>
    <system.net>
        <mailSettings>
            <smtp deliveryMethod="specifiedPickupDirectory">
                <specifiedPickupDirectory pickupDirectoryLocation="path to a directory" />
            </smtp>
        </mailSettings>
    </system.net>
</configuration>

MSDN reference - app.config mailSettings element http://msdn.microsoft.com/en-us/library/w355a94k.aspx

Solution 3:

The smtp4dev project is another dummy SMTP server. I like it because it has a nice, simple UI that logs the messages and lets you view the contents of recent messages. Written in C# with an MSI installer. Source code is available.

Solution 4:

For .NET guys out there. Keeping it simple.

We were looking into this and then one of the developers remembered about a the config setting that allows you to override how the emails are sent.

This will create a file per email and leave it alone.

<system.net>
    <mailSettings>
      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <specifiedPickupDirectory pickupDirectoryLocation="\\SharedFolder\MailDrop\" />
      </smtp>      
    </mailSettings>
  </system.net>

Solution 5:

I think the blog post A Simple SMTP Server Mock for .NET gives you what you need: a SMTP server mock

A SMTP server mock is basically a fake SMTP server which can be used for unit testing of applications which send email messages.

Also, a google search for smtp mock server will provide you with a selection of SMTP servers for testing purposes. Like:

  • Dumbster - Java fake SMTP server
  • nDumbster - .NET port of Dumbster