简体   繁体   中英

Email sent still contains HTML tags.

I'm sending an email to people using a template. The problem is that all the tags are being shown.

<p>Hello,</p>

<p> Please, click the following link to change your password </p>
//...
<p> PLEASE DO NOT REPLY TO THIS MESSAGE</p>

The mail received is displaying exactly the original message with all the tags. Is there a way to make it look like

Here's my code:

string path = System.Web.HttpContext.Current.Server.MapPath("~/path/myTemplate.txt");
String body;
using (StreamReader sr = new StreamReader(path))
{
   body = sr.ReadToEnd();
}

body = body.Replace("<%PasswordLink%>", pwdLink);

var mail = new MailMessage("from", "to");
mail.Subject = "Password Reset";
mail.Priority = MailPriority.High;
mail.Body = body;

var client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Host = "123.45.67.89";
client.Send(mail);

You need to state that the mail message is HTML. If your using System.Web.Mail.MailMessage then use:

mail.BodyFormat = MailFormat.Html;

If you're using System.Net.Mail.MailMessage then use:

mail.IsBodyHtml = true;

Add mail.IsBodyHtml = true;

This will enable HTML formatting for the email.

我想你必须将邮件正文定义为HTML:

mail.IsBodyHtml = true;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM