我試圖從我的程序發送郵件與MailDefinition類。當我嵌入一些簡單的html時它工作正常。我的代碼如下:發送電子郵件與C#中的HTML顯示額外的空格
MailDefinition md = new MailDefinition();
md.From = "me";
md.IsBodyHtml = true;
md.Subject = "Test of MailDefinition";
string body = System.IO.File.ReadAllText(@"C:\my.html");
MailMessage msg = md.CreateMailMessage("[email protected]", replacements, body, new System.Web.UI.Control());
NetworkCredential loginInfo = new NetworkCredential("me.mail", "password");
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = loginInfo;
smtp.Send(msg);
就像我說的,這似乎工作正常。但是當我嘗試發送一些更復雜的HTML在瀏覽器中看起來不錯時,我看起來有點不同。我的html:
<body>
<table cellspacing="0" cellpadding="0" style="width: 640px;">
<tr>
<td colspan="3"><img src=srctop.png /></td>
</tr>
<tr>
<td colspan="3"><img src=srcbellowtop.png /></td>
</tr>
<tr>
<td><img src=srcleft.png /></td>
<td valign="top"><p>Lorem ipsum</p>
</td>
<td><img align="right" src=srcright.png style="height:675px;"/></td>
</tr>
<tr>
<td colspan=3><img src=srccontinuous.png /></td>
</tr>
<tr>
<td colspan=3><img src=srcfooter.png /></td>
</tr>
</table>
</body>
問題是,在這封電子郵件中,我得到了頂部圖片和波峯圖片之間的白色空間。在吼吼扇和左邊的&右圖之間也有白色空間。 居然還有所有圖像之間的白色空間:S
任何想法是什麼原因造成這一點,如何解決呢?
鏈接:在瀏覽器中的Gmail http://shrani.si/f/22/OJ/1kNF0emE/ingmail.png 在瀏覽器http://shrani.si/f/20/Eu/3PrPlUnw/inbrowser.png
excpect元素:
table[Attributes Style] {
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
border-spacing: 0px;
}
user agent stylesheettable {
white-space: normal;
line-height: normal;
font-weight: normal;
font-size: medium;
font-variant: normal;
font-style: normal;
color: -webkit-text;
text-align: -webkit-auto;
}
user agent stylesheettable {
display: table;
border-collapse: separate;
border-spacing: 2px;
border-color: gray;
}
,並在Gmail:
element.style {
width: 640px;
}
Matched CSS Rules
table[Attributes Style] {
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
border-spacing: 0px;
}
user agent stylesheettable {
display: table;
border-collapse: separate;
border-spacing: 2px;
border-color: gray;
}
歡迎來到電子郵件客戶端地獄,唯一的地方是你的結果比在Web瀏覽器中預測的要少。我會開始確保引用src屬性的值引用。 –
這不是'c#'問題這是一個HTML電子郵件格式問題。我會更具體地說明哪些電子郵件客戶端無法使用。從你所說的話來看,這聽起來像是你只是想從你的細胞中取出邊界。 – James
我試圖在Gmail中打開電子郵件...是的,他們被引用... – gabrjan