2017-02-15 49 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> 

应该足够