2014-09-03 193 views
0

我在我的C#應用​​程序中使用以下格式添加一些格式到正在發送的電子郵件中。它在我的手機客戶端電子郵件android和ios以及outlook 2011 for mac中顯示得很好,但我沒有在Outlook 2013中自己獲取任何格式。我已經看過www.campaignmonitor.com/css,以爲我擁有了一切工作correctlt在Outlook 2013中的C#System.Net.Mail CSS錯誤

public static void Send_Email() 
    { 
     StringBuilder sb = new StringBuilder(); 
     StreamReader sr = new StreamReader("Email.css"); 
     string[] files = Directory.GetFiles(sDirectory + "-" + sSearchTerm); 

     MailMessage mail = new MailMessage(); 
     SmtpClient SmtpServer = new SmtpClient("<out bound server>"); 

     mail.From = new MailAddress("<from address>"); 
     mail.To.Add(sEmailAddress); 
     mail.Subject = "Logs from " + Environment.GetEnvironmentVariable("COMPUTERNAME") + " searched " + sDate + " for " + sSearchTerm; 

     sb.AppendLine("<table>"); 

     sb.AppendLine("</table>"); 

     sb.AppendLine("<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>"); 
     sb.AppendLine("<html>"); 
     sb.AppendLine("<head>"); 
     sb.AppendLine("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>"); 
     sb.AppendLine("<style type='text/css'>"); 
     string line; 
     while ((line = sr.ReadLine()) != null) 
     { 
      sb.AppendLine(line); 
     } 
     sb.AppendLine("</style>"); 
     sb.AppendLine("</head>"); 
     sb.AppendLine("<body>"); 
     sb.AppendLine("Here are the list of files on <b>" + Environment.GetEnvironmentVariable("COMPUTERNAME") + "</b> for date " + sDate + " that contain(s) <b><i>" + sSearchTerm + "</i></b><br/><br/>"); 
     sb.AppendLine("<table>"); 
     sb.AppendLine(" <tr>"); 
     sb.AppendLine(" <th>Filename</th>"); 
     sb.AppendLine(" </tr>"); 

     foreach (var file in files) 
     { 
      sb.AppendLine("<tr><td>" + Path.GetFileName(file) + "</td></tr>"); 
     } 

     sb.AppendLine("</table>"); 
     sb.AppendLine("</body>"); 
     sb.AppendLine("</html>"); 

     mail.IsBodyHtml = true; 

     mail.Body = sb.ToString(); 
     SmtpServer.Port = 587; 
     SmtpServer.Credentials = new NetworkCredential("<user>", "<pass>"); 
     SmtpServer.EnableSsl = true; 

     SmtpServer.Send(mail); 
    } 

這裏是CSS我解析在

table, thead, th, tr, td { 
    border: 1px solid black; 
    padding:5px; 
    border-collapse:collapse; 
    } 

table { 
    margin-bottom:10px; 
} 

th { 
    background:grey; 
    color:white; 
} 

tbody tr:nth-child(even) { 
    background-color: #bada55; 
} 

tbody tr:nth-child(odd) { 
    background-color: lightblue; 
} 

這裏是消息背後的HTML代碼顯示

<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'  'http://www.w3.org/TR/html4/loose.dtd'><html><head> 
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> 
<style type="text/css"> 
table, thead, th, tr, td { 
    border: 1px solid black; 
    padding:5px; 
    border-collapse:collapse; 
} 

table { 
    margin-bottom:10px; 
} 

th { 
    background:grey; 
    color:white; 
} 

tbody tr:nth-child(even) { 
    background-color: #bada55; 
} 

tbody tr:nth-child(odd) { 
    background-color: lightblue; 
} 
</style> 
</head> 
<body> 
Here are the list of files on <b>CO200197L</b> for date 2014-09-02 that contain(s) <b><i>c</i>  </b><br><br> 
<table> 
<tr> 
    <th>Filename</th> 
</tr> 
<tr><td>inin.bcf.smartclient.ininlog</td></tr> 
<tr><td>inin.updateclientapp.ininlog</td></tr> 
<tr><td>interactionclient.ininlog</td></tr> 
<tr><td>screencaptureclientu.ininlog</td></tr> 
<tr><td>screencaptureclientu_1.ininlog</td></tr> 
</table> 
</body> 
</html> 

以下是結果前兩張圖片是outlook 2013/owa,其他都是移動電子郵件和outlook的mac

Outlook OWA IOS - how its supposed to look Outlook 2011 - mac

任何想法?

回答

1

使用內聯樣式(即style屬性)而不是style元素。