Sending an HTML Email with Visual Studio 2005
Question: I am trying to send an email with Visual Studio 2005 using System.Web.Mail and it keeps telling me that it is obsolete? What should I use? Also if you have an example of how to send an HTML email that would also help.
Answer: Within Visual Studio 2005 you can use the System.Net.Mail namespace. This contains the classes used to send email using SMTP. The MailMessage class is used to represent the content of an email message. The SmtpClient transmits email to the SMTP host that you designate for mail delivery. For example you can use the following code within a button of a Windows form to send an HTML email.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim client As New SmtpClient("smtp.server")
Dim toAddr As New MailAddress(trobbins@microsoft.com)
Dim fromAddr As New MailAddress(trobbins@microsoft.com)
Dim message As New MailMessage(fromAddr, toAddr)
message.IsBodyHtml = True
message.Subject = "This is a Test"
message.Body = "<html><body><b>This is an </b> <font color=red>HTML Message</font></body></html> "
client.Send(message)
End Sub
The email that is sent looks like the following
