Send HTML email via C# with SmtpClient

user34537 picture user34537 · Aug 25, 2009 · Viewed 61.9k times · Source

How do I send an HTML email? I use the code in this answer to send emails with SmtpClient, but they're always plain text, so the link in the example message below is not formatted as such.

<p>Welcome to SiteName. To activate your account, visit this URL: <a href="http://SiteName.com/a?key=1234">http://SiteName.com/a?key=1234</a>.</p>

How do I enable HTML in the e-mail messages I send?

Answer

Josiah Peters picture Josiah Peters · Aug 25, 2009

This is what I do:

MailMessage mail = new MailMessage(from, to, subject, message);
mail.IsBodyHtml = true;
SmtpClient client = new SmtpClient("localhost");
client.Send(mail);

Note that I set the mail message html to true: mail.IsBodyHtml = true;