我正在使用模板向人们发送电子邮件。问题是所有的标签都被显示了。
<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);
最佳答案
您需要声明邮件消息是 HTML。如果您使用 System.Web.Mail.MailMessage然后使用:
mail.BodyFormat = MailFormat.Html;
如果您使用 System.Net.Mail.MailMessage然后使用:
mail.IsBodyHtml = true;
关于c# - 发送的电子邮件仍然包含 HTML 标签。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40512176/