Testing SMTP with .net

I need to set up an SMTP server to test my website, which sends emails (to confirm registration, etc.).

I really do not want the letter to be sent, I just want to make sure my code is correct. So I want to check that the email is placed in the queue folder, for example.

Can I recommend an SMTP server that is easy to configure?

+51
smtp testing
Feb 15 '09 at 13:40
source share
16 answers

There's also Papercut , which is an SMTP server that will receive messages but does not deliver them anywhere (letting you make sure they are sent correctly). Received messages are displayed in a small graphical interface and are also written to the directory.

+41
Feb 15 '09 at 2:00
source share

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

The default constructor for SmtpClient accepts 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 link - app.config mailSettings element http://msdn.microsoft.com/en-us/library/w355a94k.aspx

+27
Feb 18 2018-10-18
source share

The smtp4dev project is another dummy SMTP server. I like it because it has a simple, simple user interface that logs messages and allows you to view the contents of recent messages. It is written in C # with the MSI installer. Source code is available.

+19
Nov 02 '09 at 22:44
source share

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

The layout of an SMTP server is basically a fake SMTP server that can be used to block testing applications that send email messages.

In addition, google search for smtp mock server will provide you with a selection of SMTP servers for testing. How:

+7
Feb 15 '09 at 13:53
source share

For .NET guys. Keeping it simple.

We studied this, and then one of the developers remembered a configuration setting that allows you to override the way you send email messages.

This will create the file by email and leave it alone.

 <system.net> <mailSettings> <smtp deliveryMethod="SpecifiedPickupDirectory"> <specifiedPickupDirectory pickupDirectoryLocation="\\SharedFolder\MailDrop\" /> </smtp> </mailSettings> </system.net> 
+7
Feb 18 2018-10-18
source share

An alternative way to do this is to create a wrapper around SmtpClient that implements the same interface. Then paste and use the wrapper in your class. When doing unit testing, you can then replace the mock shell that has expectations for method calls and responses.

EDIT . A shell is required (for RhinoMocks, at least), because SmtpClient is not derived from the interface and does not have virtual methods. If you use a fake framework that can mock a class without virtual methods directly, you can skip the shell and immediately enter the SmtpClient layout.

 public class SmtpClientWrapper { private SmtpClient Client { get; set; } public SmtpClientWrapper( SmtpClient client ) { this.Client = client; } public virtual void Send( MailMessage msg ) { this.Client.Send( msg ); } ... } public class MyClass { private SmtpClientWrapper Client { get; set; } public MyClass( SmtpClientWrapper client ) { this.Client = client; } public void DoSomethingAndNotify() { ... this.Client.Send( msg ); } } 

Tested (with RhinoMocks) as:

 public void DoSomethingAndNotifySendsAMessageTest() { SmtpClientWrapper client = MockRepository.GenerateMock<SmtpClientWrapper>(); client.Expect( c => c.Send( new MailMessage() ) ).IgnoreArguments(); MyClass klass = new MyClass( client ); klass.DoSomethingAndNotify(); client.VerifyAllExpectations(); } 
+4
Feb 15 '09 at 13:57
source share

I found this - http://improve.dk/archive/2010/07/01/papercut-vs-smtp4dev-testing-mail-sending-locally.aspx , which explains how to use papercut and smtp4dev, which are good tools

+3
Jul 22 '11 at 7:50
source share

I use Antix SMTP Server for developers , which is as simple as opening an application. It saves messages in a folder, and you can view them using the user interface. Pretty quick / easy solution. I wanted to mention it here.

See also: development smtp server for Windows

+3
Nov 07 2018-11-11T00:
source share

The DevNull SMTP server logs all the details of the connection between the client and the SMTP server. It seems like it would be helpful if you were trying to diagnose why your submit code did not work.

It is written in Java and is deployed as an executable ATM. Source code seems unavailable.

+2
Nov 02 '09 at 22:40
source share

If you are on Mac OS X, you can use MockSMTP.app

+2
Jan 19 '10 at 6:26
source share

You can also use netDumbster.

http://netdumbster.codeplex.com/

+2
May 18 '10 at 8:13
source share

there is also my own http://ssfd.codeplex.com/ , which is an open source SMTP emulator. Receive email and drop them into a folder that can be accessed using the task icon

0
Nov 03 '09 at 8:49
source share

Please note that the smtpClientWrapper class proposed by tvanfosson needs all the important keyword “virtual” in its declaration of the sending method, otherwise you will return to the same boat as when trying to directly bind SmtpClient.

0
Dec 01 2018-10-12T00:
source share

According to many other suggestions, a free tool that I used quite a lot: http://www.toolheap.com/test-mail-server-tool/

Not for TDD, but useful for manual testing, as it may pop up in the Outlook Quick View window with every email sent.

0
Jul 16 2018-11-11T00:
source share

If you have Python installed, you can run the following one liner to start the debug smtp server in the console, which will print messages to standard output:

sudo python -m smtpd -n -c Debug Server Localhost: 25

stuck from here: http://muffinresearch.co.uk/archives/2010/10/15/fake-smtp-server-with-python/

0
May 31 '12 at 14:52
source share

As Sean Carpenter noted, Papercut is a powerful local development solution. However, if you also run a setup or testing server, mailtrap.io may be a simpler solution in general, because you can use the same approach for your dev and intermediate environments.

0
Jul 03 '15 at 13:39
source share



All Articles