Did you know that you can configure the built-in System.Net.Mail.SmtpClient to drop emails into a location on disk? This means that you don’t need an SMTP server for testing the email sending capabilities of your application.
You can find this advice in numerous places on the interweb, but I need to make a note here because every time I want to do it, I can’t remember the details and have to waste time browsing for it.
Simply put this configuration section in your App.config or Web.config file:
Now when you have some code like this:
var smtpClient = new SmtpClient();
var message = new MailMessage("firstname.lastname@example.org", "email@example.com")
Subject = "The subject",
Body = "The body of the message"
You get a file deposited in C:\temp\maildrop called something like ec40a365-270f-49ac-9aa5-1e68ec6a4df1.eml that looks like this:
Date: 27 Jan 2010 21:32:05 +0000
Subject: The subject
Content-Type: text/plain; charset=us-ascii
The body of the message