[英]Email sent still contains HTML tags.
我正在向使用模板的人發送電子郵件。 問題是所有標簽都在顯示。
<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;
添加mail.IsBodyHtml = true;
這將為電子郵件啟用HTML格式。
我想你必須將郵件正文定義為HTML:
mail.IsBodyHtml = true;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.