我正在尝试从我的程序中发送一封包含MailDefinition类的电子邮件。当我嵌入一些简单的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("me@gmail.com", 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>问题是,在这封电子邮件中,我在上面的图片和下面的图片之间有一个空白。下面和左边和右边的图片之间也有空白。实际上,所有图像之间都有空格:
你知道是什么原因造成的吗?如何修复它?
链接:在浏览器http://shrani.si/f/20/Eu/3PrPlUnw/inbrowser.png中的gmail http://shrani.si/f/22/OJ/1kNF0emE/ingmail.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;
}发布于 2012-10-02 18:25:35
正如你已经澄清的问题发生在Gmail中,你能做的最好的事情就是使用你计划支持的各种浏览器的相关开发工具来检查应用于电子邮件的HTML/CSS。
IE - How to use F12 Developer Tools to Debug your Webpages
火狐- Firebug
这将允许您缩小问题的范围,并确定是您自己的样式,还是由浏览器/客户端添加的样式。
更新
查看你的源代码,问题似乎是你的图片被浏览器视为inline-block,将它们设置为display: block应该可以解决这个问题。
https://stackoverflow.com/questions/12688203
复制相似问题