【问题标题】:unable to get css when sending email with css使用 css 发送电子邮件时无法获取 css
【发布时间】:2017-11-26 10:40:59
【问题描述】:

有什么方法可以从 c# asp.net 发送一封带有 css html 页面的电子邮件。

目前我正在发送电子邮件,但是当我在 gmail 中打开时,它不会捕获 htmlpage 中包含的 css

<html>
  <head>
    <meta charset="utf-8" />
    <title></title>
  <style>
    body{
        background-color:navy;
        color:white;
        font-family:Menulis;
        margin-left:40px;
    }

    div {
        margin:0 auto;
    }

    img{
        border-radius:5px;
        width:200px;
        height:300px;
        margin-right:200px;
        display:block;
        float:right;
    }

 </style>
 </head>

<body>
<div>
    <h1>User {user_email} Error Report</h1>
    <p>The following error occured when user is trying to reset password     

  from pswrd_recover.aspx page:</p><br/>
    <img src="https://pcappliancerepair.files.wordpress.com/2016/11 
 /38644550_m.jpg?w=585"/>
    <p>{error_message}</p>

  </div>
 </body>
 </html>

【问题讨论】:

    标签: c# html css email


    【解决方案1】:

    Gmail 会删除电子邮件 HTML 的整个 head 部分。因此,它还将删除所有 style 元素。 您需要内联您的 CSS,如下所示:

    <body style="background-color:navy; color:white;font-family:Menulis;margin-left:40px;">
    <div style="margin:0 auto;">...</div>
    <img style="border-radius:5px;width:200px;height:300px;margin-right:200px;display:block;float:right;" src="https://..." />
    </body>
    

    【讨论】:

    • &lt;style&gt; 标签可以在&lt;body&gt; 元素内使用
    猜你喜欢
    • 2022-12-28
    • 2016-09-18
    • 2014-09-23
    • 1970-01-01
    • 2015-10-09
    • 2010-11-12
    • 1970-01-01
    • 1970-01-01
    • 2015-06-11
    相关资源
    最近更新 更多