Google Search


Saturday, December 8, 2007

Sending Email with ASP.NET 2.0

In ASP.Net 2.0 use System.Net.Mail class.

System.Net.Mail is the namespace used to send email if you are using the 2.0 (or higher) .NET Framework.

Unlike System.Web.Mail, which was introduced in the 1.0 Framework, it is not built upon the CDO/CDOSYS libraries. Instead it is written from the ground up without any interop. Thus, it is not dependant upon other COM libraries. System.Net.Mail introduces brand new classes for creating and sending email.

Although some functionality has been removed, the new System.Net.Mail namespace is much more versatile than the older CDO dependant System.Web.Mail.

Dim message As MailMessage = New MailMessage()
message.From = New MailAddress("", "From Name")

message.ReplyTo = New MailAddress("", "ReplyTo Name")

message.To.Add(New MailAddress("", "Name One"))
message.To.Add(New MailAddress("", "Name Two"))
message.CC.Add(New MailAddress("", "CC Name"))
message.Bcc.Add(New MailAddress("", "BCC Name"))

message.Subject = "Subject"
message.Body = "This is a plain text"
message.IsBodyHtml = False

'Priority property can have next values: Low, Normal and High.
message.Priority = MailPriority.Normal

Dim emailClient As New SmtpClient("")