Sending Mail with the ASP.NET Web Matrix
(Page 1 of 4 )
The MS ASP.NET Web Matrix application has a number of code wizards, covered in previous articles. This one covers the EMAIL message code generator. It is surprisingly useful for adding contact page functionality to a website; your visitors will appreciate being able to interact with you in this manner. Dan Wellman explains how to set it up.
The previous articles looked at the built-in code wizards that come with the MS ASP.NET Web Matrix application. (You can find the most recent of these articles here). These code generators are included to make performing basic database operations with ASP.NET extremely easy to do and can simplify the learning process or cut down on design time. We’ve covered all four of the basic database operations in the previous four articles, but there remains one code wizard that has not yet been used: the EMAIL message code generator.
Many websites feature a contact page that will let a user enter a message into the page and then have the application send the email to the address specified in the email function parameters. This may be for technical support, help and advice, or to request information. Whatever the reason, the ASP.NET Web Matrix makes adding this functionality to a site extremely easy, and is exactly what we’re going to do.
For conclusive testing of this feature, you are going to need to have and use IIS (5.1 ideally). If you have Norton, or another application able to scan all email for viruses, you will know it has worked when you get a popup advising that the mail is being scanned, but to be able to receive an email in your domain and view it, IIS is required.
This part is simple, so let’s get it out of the way first; open IIS, expand the Default SMTP Virtual Server and select Domains. There should be a default domain already set up, but you can create a new one for the purpose of this article by right-clicking anywhere in the right-hand pane of IIS and selecting New > Domain.

This action will generate an instance of the New SMTP Domain wizard. Set the radio to Alias and then click Next. Choose a name for your domain, dudemail.com will be sufficient, and click Finish. Your domain will now appear in the domain list of IIS. That is it. All incoming mail for this domain will be stored in a folder called Drop, which resides in the mailroot folder of Inetpub.
Next: Creating the Page >>
More ASP.NET Articles
More By Dan Wellman