MailMessage c# - How to make it HTML and add images etc?

Beginner picture Beginner · Oct 24, 2011 · Viewed 26.9k times · Source
string to = "[email protected]";
 string body = "Test";
 SmtpClient SMTPServer = new SmtpClient("127.0.0.1");
 MailMessage mailObj = new MailMessage(urEmail, to, subject, body);
 SMTPServer.Send(mailObj);

This is how i am currently sending a test email. How do i make this html and be able to make the email sent out look better by adding images etc?

Thanks

Answer

swapneel picture swapneel · Oct 24, 2011

On the MailMessage set the property IsBodyHtml to true.

string to = "[email protected]";
string body = "Test";
SmtpClient SMTPServer = new SmtpClient("127.0.0.1");
MailMessage mailObj = new MailMessage(urEmail, to, subject, body);

mailObj.IsBodyHtml = true; // This line

SMTPServer.Send(mailObj);