プログラムから 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>
問題は、このメールでトップの画像とベロートップの画像の間に空白ができることです。また、ベロートップと左右の写真の間に空白があります。実際には、すべての画像の間に空白があります:S
それを引き起こしている原因とそれを修正する方法はありますか?
リンク: Gmailでhttp://shrani.si/f/22/OJ/1kNF0emE/ingmail.png ブラウザでhttp://shrani.si/f/20/Eu/3PrPlUnw/inbrowser.png
ブラウザの要素を期待:
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;
}