9.2. Processing Data at the Server

The information that a user inputs on your Web Forms is typically not the only data that makes your web site an interactive, data-driven system. In most web sites, you have information coming from other data sources as well, such as databases, text, XML files, and web services. In addition, there is also data going out of your system. You may want to send an e-mail to the owner of the web site whenever someone posted information through the contact page or you may want to notify people whenever you add a new feature or review to the web site. For these scenarios, it's important to understand how ASP.NET 3.5 allows you to send e-mail. This is discussed in the next section.

9.2.1. Sending E-mail from Your Web Site

Writing code that sends e-mail from an ASP.NET page is pretty straightforward. Inside the System.Net.Mail namespace you find a number of objects that make it very easy to create and send e-mail messages. These objects allow you to create new messages; add addressees in the To, CC, and Bcc fields; add attachments; and, of course, send the messages.

The following table describes four objects that you typically work with when sending e-mail from a .NET application.

ClassDescription
MailMessageThis class represents the message you're going to send. It has properties such as Subject and Body to set the message contents; To, CC, and Bcc properties to set the addressees; and an Attachments collection to attach files to the message.
MailAddress ...

Get Beginning ASP.NET 3.5: In C# and VB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.