2017-02-15 44 views
0

我有以下代碼:C# - 電子郵件作爲HTML不工作

MailMessage mail = new MailMessage(); 
SmtpClient SmtpServer = new SmtpClient(Properties.Settings.Default.smtpServer); 
mail.From = new MailAddress(Properties.Settings.Default.mailFrom); 
mail.To.Add(mailto); 
if (!string.IsNullOrEmpty(CC)) { 
mail.CC.Add(CC); 
}; 
mail.Subject = subject; 
mail.IsBodyHtml = true; 
mail.Body = body; 
mail.Priority = MailPriority.High; 
mail.To.Add(mailto); 
SmtpServer.EnableSsl = Properties.Settings.Default.SSL; 
SmtpServer.UseDefaultCredentials = false; 
SmtpServer.Port = Properties.Settings.Default.smtpPort; 
SmtpServer.Credentials = new System.Net.NetworkCredential(Properties.Settings.Default.Username,  Properties.Settings.Default.emailPassword); 
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network; 
SmtpServer.Timeout = 200000; 
SmtpServer.Send(mail); 
markEmailAsSent(uid); 

我嘗試發送以下爲HTML,但郵件沒有被髮送,所以,我收到了原始的HTML回來。我已包括mail.IsBodyHtml = true;所以我不知道爲什麼這不起作用。

這裏是消息的內容:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Trilogy</title> 
<style type="text/css"> 
<!-- 
.style1 {color: #F33621} 
.style4 {font-family: Arial} 
.style6 { 
    font-family: Arial; 
    font-size: 11pt; 
    color: #A2A2A2; 
} 
.style7 { 
    font-family: "Agency FB"; 
    color: #FFAF9A; 
    font-size: 10.5pt; 
} 
.style8 { 
    font-family: Arial; 
    font-size: 11pt; 
} 
.style9 { 
    font-size: 11pt 
} 
.header { 
    font-family: Arial, Helvetica, sans-serif; 
    font-size: 24px; 
    font-weight: bold; 
} 
--> 
</style> 
</head> 
<body> 
<p align="left" class="style8">bla bla bla bla bla<br /> 
    <br /> 
<strong>Sometext</strong> 
<br />t: 01666 666 666 
<br />e: <a href="mailto:[email protected]3.net%</a></p> 

</body> 
</html> 
+0

是什麼'body'看起來像在代碼 – Laazo

+0

'mailto'缺失報價BTW –

+0

使用'AlternateView'例如http://stackoverflow.com/questions/2555813/what-does-mailmessage-isbodyhtml-do –

回答

0

更改HTML到:

<html> <head> <title>Trilogy</title> <style type="text/css"> </style> </head> <body> <p align="left" class="style8">bla bla bla bla bla<br /> <br /> <strong>Sometext</strong> <br />t: 01666 666 666 <br />e: <a href="mailto:[email protected]"</a></p> 

</body> </html> 
0

據做到規範,這一點;

<p align="left" class="style8">bla bla bla bla bla<br /> 
<br /> 
<strong>Sometext</strong> 
<br />t: 01666 666 666 
<br />e: <a href="mailto:[email protected]"</a></p> 

應該足夠