c# MailMessage HTML string style='margin-bottom:-2px' 不起作用
c# MailMessage HTML string style='margin-bottom:-2px' doesn't work
我正在创建一封邮件,我将一些 HTML 代码放在一个字符串(邮件正文)中,该字符串将被发送到 AlternativeView(设置到 MailMessage 中)。
问题是我在图像中添加了 margin-bottom
的样式属性,但它对收到的邮件 (Gmail) 没有任何影响。
检查图片对象进入Gmail后,样式属性好像消失了。
这是 html 内容(由我的测试应用程序生成)在发送邮件之前通过断点进入调试状态:
<h2><strong>Ratio :</strong> 80%<br><strong>Total Tests Count :</strong> 5<br /><strong>Total Tests Pass :</strong> 4</h2>
<br>
<hr>
<br>
<h2> <img src='cid:imgUITPR' width="16" height="16"/><strong> UITestPlan </strong > 'AssignHoursProfileToDriver' (TestSuites : 3) : <font color='#FF5252'>Failed</font></h2>
<h3> <img src='cid:imgUITSR' width="16" height="16" style='margin-bottom: -2px;' /><strong > UITestSuite </strong > 'CreateDriver' (Tests : 4) : <font color='#FF5252'>Failed</font></h3>
<h4> <img style='margin-bottom: -3px;' src='cid:imgUITG' width="16" height="16" /><strong > UITest </strong > 'OpenDriversModule' (Steps : 1) : <font color='#4CAF50'>Pass</font></h4>
<h4> <img style='margin-bottom: -3px;' src='cid:imgUITG' width="16" height="16" /><strong > UITest </strong > 'ClickOnCreateDriver' (Steps : 1) : <font color='#4CAF50'>Pass</font></h4>
<h4> <img style='margin-bottom: -3px;' src='cid:imgUITG' width="16" height="16" /><strong > UITest </strong > 'FillNewDriverDetails' (Steps : 4) : <font color='#4CAF50'>Pass</font></h4>
<h4> <img style='margin-bottom: -3px;' src='cid:imgUITR' width="16" height="16" /><strong > UITest </strong > 'ClickOnValidate' (Steps : 1) : <font color='#FF5252'>Failed</font></h4>
<h3> <img src='cid:imgUITS' width="16" height="16" style='margin-bottom: -2px;' /><strong > UITestSuite </strong > 'CreateHoursProfile' (Tests : 1) : <strong>Ignored</strong></h3>
<h4> <img style='margin-bottom: -3px;' src='cid:imgUIT' width="16" height="16" /><strong > UITest </strong > 'OpenConfigurationModule' (Steps : 1) : <strong>Ignored</strong></h4>
<h3> <img src='cid:imgUITS' width="16" height="16" style='margin-bottom: -2px;' /><strong > UITestSuite </strong > 'AssignProfileToDriver' (Tests : 0) : <strong>Ignored</strong></h3>
编辑:
我使用负边距,Gmail as Outlook 和 Yahoo 不支持负边距。
我在这个 blog post 中看到了第 9 点:
Gmail does not allow negative CSS margin values
网络邮件客户端似乎倾向于完全忽略边距。
我正在创建一封邮件,我将一些 HTML 代码放在一个字符串(邮件正文)中,该字符串将被发送到 AlternativeView(设置到 MailMessage 中)。
问题是我在图像中添加了 margin-bottom
的样式属性,但它对收到的邮件 (Gmail) 没有任何影响。
检查图片对象进入Gmail后,样式属性好像消失了。
这是 html 内容(由我的测试应用程序生成)在发送邮件之前通过断点进入调试状态:
<h2><strong>Ratio :</strong> 80%<br><strong>Total Tests Count :</strong> 5<br /><strong>Total Tests Pass :</strong> 4</h2>
<br>
<hr>
<br>
<h2> <img src='cid:imgUITPR' width="16" height="16"/><strong> UITestPlan </strong > 'AssignHoursProfileToDriver' (TestSuites : 3) : <font color='#FF5252'>Failed</font></h2>
<h3> <img src='cid:imgUITSR' width="16" height="16" style='margin-bottom: -2px;' /><strong > UITestSuite </strong > 'CreateDriver' (Tests : 4) : <font color='#FF5252'>Failed</font></h3>
<h4> <img style='margin-bottom: -3px;' src='cid:imgUITG' width="16" height="16" /><strong > UITest </strong > 'OpenDriversModule' (Steps : 1) : <font color='#4CAF50'>Pass</font></h4>
<h4> <img style='margin-bottom: -3px;' src='cid:imgUITG' width="16" height="16" /><strong > UITest </strong > 'ClickOnCreateDriver' (Steps : 1) : <font color='#4CAF50'>Pass</font></h4>
<h4> <img style='margin-bottom: -3px;' src='cid:imgUITG' width="16" height="16" /><strong > UITest </strong > 'FillNewDriverDetails' (Steps : 4) : <font color='#4CAF50'>Pass</font></h4>
<h4> <img style='margin-bottom: -3px;' src='cid:imgUITR' width="16" height="16" /><strong > UITest </strong > 'ClickOnValidate' (Steps : 1) : <font color='#FF5252'>Failed</font></h4>
<h3> <img src='cid:imgUITS' width="16" height="16" style='margin-bottom: -2px;' /><strong > UITestSuite </strong > 'CreateHoursProfile' (Tests : 1) : <strong>Ignored</strong></h3>
<h4> <img style='margin-bottom: -3px;' src='cid:imgUIT' width="16" height="16" /><strong > UITest </strong > 'OpenConfigurationModule' (Steps : 1) : <strong>Ignored</strong></h4>
<h3> <img src='cid:imgUITS' width="16" height="16" style='margin-bottom: -2px;' /><strong > UITestSuite </strong > 'AssignProfileToDriver' (Tests : 0) : <strong>Ignored</strong></h3>
编辑: 我使用负边距,Gmail as Outlook 和 Yahoo 不支持负边距。
我在这个 blog post 中看到了第 9 点:
Gmail does not allow negative CSS margin values
网络邮件客户端似乎倾向于完全忽略边距。