Test Email Delivery Methods in web.config Using ASP.net

Among the most common items in a web site is the implementation of email.  There are many ways of implementing email from a web site.  You can use a multitude of technologies to accomplish this.  This article is not to discuss different methods but to look at one method which is asp.net.  You could just set the settings (server, login, password, etc) in code and use the standard SMTP code that so many sites put together, however; I have found this to be cumbersome when you are deploying the site to production.  Furthermore; after you publish to production any further testing will mingle the production emails among the testing emails.  So what can you do to make this an easier transition?  If you are familiar with VS 2012 transformation then you can see where I am going.  If not then be prepared to learn something new today.

  1. Start by creating a VS2012 project.
(figure 1)

2.   Once you have done this then your solution explorer should look like figure 2.

3.  Click on ‘Show All files’ (figure 2)


4.  Open your web.config file and enter the following;

[sourcecode language=”xml”]
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="D:\XXXXXXXXXXX"/>

Note: This will create the email and save it in the D:\ drive.  The nice thing about this is that you can then use Outlook, or Thunderbird to actually open the file to test your output (email) without it actually sending anything but a file email. 

5.  Open up Web.Release.config and add the following;

[sourcecode language=”xml”]
<mailSettings xdt:Transform="Replace">
<smtp deliveryMethod="Network">
<network host="mail.MAILSERVER.com" port="25" userName="EMAILADDRESS" password="XXXXXX"/>

Note: At Arvixe this is typically your server name

6.  When you compile or deploy, change your compiler instance (figure 3).  This will transform the web.config to the new method.

Figure3(figure 3)
Looking for quality web hosting? Look no further than Arvixe Web Hosting!
Tags: , , , , , , , , | Posted under ASP .NET 3.5, Webmail, YetAnotherForum.NET | RSS 2.0

Author Spotlight

David Bauernschmidt

I live in the historical triangle of Virginia where I am married with two daughters. I have spent over 13 years working for a Fortune 500 company in the computer area. I started in VB 6.0 and by the time I ended my employment I was supervising a development team where we built many web applications. When my first daughter was born I wanted to spend more time with her so I left and became a programmer analyst for local government as well as launch my own company. Since then I have grown James River Webs into a profitable web design and application company helping small businesses create a big presence on the internet. As an employee I have created web application used by citizens and other companies. I enjoy fly fishing, and spending time with my family. I also enjoy learning new approaches and development tools when it comes to developing applications.

One Comment on Test Email Delivery Methods in web.config Using ASP.net

  1. ayush says:

    Am taking the daily backup using task scheduler so my requirement is whenever the backup is exceeds its limit (for eg:we fix it 500 mb) so it sends an email to the user.HOw it can be possible.Any Help ?

    Thanks in Advance !!

Leave a Reply

Your email address will not be published. Required fields are marked *