Let’s imagine the following scenario: You are developing a feature that creates e-mail messages and you want to quickly test if the e-mail format is ok. To achieve that you may specify a directory where the messages will be saved so instead of trying to access the smtp server you are going to save the file that you can view in Outlook.
- On your application’s configuration file add a smtp section and set the deliveryMethod attribute to “SpecifiedPickupDirectory”;
- Specify a directory to save the messages by adding a specifiedPickupDirectory element and setting the pickupDirectoryLocation attribute to a path to save the messages;
- The configuration section must be similar to the following:
<specifiedPickupDirectory pickupDirectoryLocation=“C:\MyMessages“ />
If you want to make a quick test, create a Message and a SmtpClient object. Both are available under the System.Net.Mail namespace. The code will be similar to the following:
MailMessage msg = new MailMessage(“firstname.lastname@example.org”, “email@example.com”);
msg.Body = “This is the message body.”;
msg.Subject = “This is the message subject.”;
SmtpClient smtp = new SmtpClient(string.Empty); //Empty just for testing purposes.
Check the directory you specified in the configuration file. An eml file with a guid name will be there. Just double-click on it to view the content on the Outlook.