2016-11-09 58 views
3

我正在使用模板向某人發送電子郵件。問題是所有的標籤都被顯示出來。發送的電子郵件仍包含HTML標記。

<p>Hello,</p> 

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

收到的郵件正在顯示包含所有標籤的原始郵件。有沒有一種方法,以使它看起來像

這裏是我的代碼:您需要說明的是,郵件是HTML

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); 
+0

你要做'mail.IsBodyHtml = TRUE;' – SimpleVar

回答

1

添加mail.IsBodyHtml = true;

這將使HTML格式的電子郵件。

1

我想你必須定義郵件正文爲HTML:

mail.IsBodyHtml = true;