If you have used System.Web.Mail namespace in .NET 1.x for sending emails programmatically, expect a surprise. All classes within this namespace have been deprecated in favor of the new System.Net.Mail namespace. System.Net.Mail contains classes such as MailMessage, Attachment, MailAddress, SmtpClient, etc to help us send emails in the 2.0 world. The features provided by this namespace, in a nutshell, are given below.
- MailMessage is the main class that represents an email message.
- Use MailAddress class to represent the sender and each recipient.
- Use SmtpClient class to connect to the SMTP server and send the email, both synchronously and asynchronously.
- Use AlternateView class to create the email content in alternate formats, say one in HTML and other plain text, to support different recipient types.
- Use LinkedResource class to associate an image with the email content.
- SmtpPermission class and SmtpPermissionAttribute can be used for code access security.
To know more about some of these classes, read this article.