user1093651 user1093651 - 24 days ago 7
ASP.NET (C#) Question

How to send HTML-formatted email?

I could be able to let the web application sends automatic emails using Windows Task Scheduler. Now I want to send HTML-Formatted email using the following method that I wrote for sending emails.

My code-behind:

protected void Page_Load(object sender, EventArgs e)
{
SmtpClient sc = new SmtpClient("mail address");
MailMessage msg = null;

try
{
msg = new MailMessage("xxxx@gmail.com",
"yyyy@gmail.com", "Message from PSSP System",
"This email sent by the PSSP system");

sc.Send(msg);
}

catch (Exception ex)
{
throw ex;
}

finally
{
if (msg != null)
{
msg.Dispose();
}
}
}


How to do that? I just want to put some bold text with one link and maybe one image in the email.

Answer

Setting isBodyHtml to true allows you to use HTML tags in the message body:

msg = new MailMessage("xxxx@gmail.com",
                "yyyy@gmail.com", "Message from PSSP System",
                "This email sent by the PSSP system<br />" +
                "<b>this is bold text!</b>");

msg.IsBodyHtml = true;