Sending emails is a very common activity for an application to perform. Using the System.Net section in the configuration file (app.config, web.config) to hold the settings makes things easier. There are a few different ways that the settings can be configured and I use a different method for when in development, user acceptance testing or live environments via XML transformation. I will not go into the details of XML transformations here, that is for another day.
Method 1
The first way is to send emails to localhost address 127.0.0.1.
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network defaultCredentials="true" host="127.0.0.1"/>
</smtp>
</mailSettings></system.net>
To intercept and read the email grab a dummy SMTP server such as smtp4dev which, when installed sits in the system tray. The received messages can be quickly viewed, saved and the source/structure inspected, but what I find it does not do is format emails in a reader friendly manner which can make checking HTML emails difficult.
Method 2
You can configure emails to be sent to a local folder as an .eml file.
<system.net>
<mailSettings>
<smtp deliveryMethod="specifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\maildrop"/>
</smtp>
</mailSettings>
</system.net>
To view the messages use an application such as MailView. This is my current preferred option as emails can be easily read in both plain text and HTML format. What MailView does not do is refresh the email list as they drop into the designated folder.
Method 3
You can configure the settings to work through a local network SMTP server (e.g. exchange server).
<system.net>
<mailSettings>
<smtp deliveryMethod="network">
<network host="mailserver.domain" defaultCredentials="true"/>
</smtp>
</mailSettings></system.net>
Method 4
To configure an application for hosting on a third party host
<system.net>
<mailSettings>
<smtp>
<network host="smtpout.secureserver.net"
userName="XXX@XXXcom" password="Password*" port="25"/>
</smtp>
</mailSettings>
</system.net>
For more information relating to mailsettings and descriptions on other attributes not used here see the MSDN article.


You must be logged in to post a comment.