【问题标题】:c# MailMessage HTML string style='margin-bottom:-2px' doesn't work [duplicate]c#MailMessage HTML字符串样式='margin-bottom:-2px'不起作用[重复]
【发布时间】:2019-02-19 06:56:40
【问题描述】:

我正在创建一封邮件,并将一些 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&nbsp;:</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 作为 Outlook 和 Yahoo 不支持负边距。

【问题讨论】:

  • 使用浏览器的 F12 开发人员工具检查实际应用于您的消息的样式。如果 GMail 删除了负边距,或者如果它应用了阻止您的图像正确显示的额外样式,您的代码将无法执行任何操作
  • CSS 支持因电子邮件客户端而异。 免责声明 - 我在一家帮助您设计和发送 HTML 电子邮件的公司工作。

标签: c# html html-email


【解决方案1】:

我在第 9 点看到了 blog post

Gmail 不允许负 CSS 边距值

似乎网络邮件客户端倾向于完全忽略边距。

【讨论】:

    猜你喜欢
    • 2019-02-24
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多