C# 发送的电子邮件仍然包含HTML标记。

C# 发送的电子邮件仍然包含HTML标记。,c#,asp.net,smtpclient,C#,Asp.net,Smtpclient,我正在使用模板向人们发送电子邮件。问题是所有的标签都显示出来了 <p>Hello,</p> <p> Please, click the following link to change your password </p> //... <p> PLEASE DO NOT REPLY TO THIS MESSAGE</p> 你好 请单击以下链接更改您的密码 //... 请不要回复此邮件 收到的邮件显示的正是包含所有标签的

我正在使用模板向人们发送电子邮件。问题是所有的标签都显示出来了

<p>Hello,</p>

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

请单击以下链接更改您的密码

//... 请不要回复此邮件

收到的邮件显示的正是包含所有标签的原始邮件。有没有办法让它看起来像

这是我的密码:

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);
string path=System.Web.HttpContext.Current.Server.MapPath(“~/path/myTemplate.txt”);
弦体;
使用(StreamReader sr=新StreamReader(路径))
{
body=sr.ReadToEnd();
}
body=body.Replace(“”,pwdLink);
var mail=新邮件信息(“发件人”、“收件人”);
mail.Subject=“密码重置”;
mail.Priority=MailPriority.High;
mail.Body=Body;
var client=新的SmtpClient();
客户端端口=25;
client.DeliveryMethod=SmtpDeliveryMethod.Network;
client.Host=“123.45.67.89”;
客户端。发送(邮件);

您需要声明邮件消息是HTML。如果您正在使用,请使用:

mail.BodyFormat = MailFormat.Html;
mail.IsBodyHtml = true;
如果您正在使用,请使用:

mail.BodyFormat = MailFormat.Html;
mail.IsBodyHtml = true;

添加
mail.IsBodyHtml=true


这将启用电子邮件的HTML格式。

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

mail.IsBodyHtml = true;

您必须执行
mail.IsBodyHtml=true