System.Net.Mail FAQ

Complete FAQ Listing


3.1.2 How do I send a simple Html email? Printer Friendly

By default, email sent with System.Net.Mail is formatted as plain text. To format as Html, set the MailMessage.IsBodyHtml property to true.
 
[ C# ]
 //create the mail message
 MailMessage mail = new MailMessage();

 //set the addresses
 mail.From = new MailAddress("me@mycompany.com");
 mail.To.Add("you@yourcompany.com");

 //set the content
 mail.Subject = "This is an email";
 mail.Body = "this is a sample body with html in it. <b>This is bold</b> <font color=#336699>This is blue</font>";
 mail.IsBodyHtml = true;

 //send the message
 SmtpClient smtp = new SmtpClient("127.0.0.1");
 smtp.Send(mail);



[ VB.NET ]
 'create the mail message
Dim mail As New MailMessage()

'set the addresses
mail.From = New MailAddress("me@mycompany.com")
mail.To.Add("you@yourcompany.com")

'set the content
mail.Subject = "This is an email"
 mail.Body = "this is a sample body with html in it. <b>This is bold</b> <font color=#336699>This is blue</font>"
mail.IsBodyHtml = True

'send the message
Dim smtp As New SmtpClient("127.0.0.1")
smtp.Send(mail)