c# - 使用 css 发送电子邮件时无法获取 css

标签 c# html css email

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

目前我正在发送电子邮件,但是当我在 gmail 中打开时,它没有捕获 html 页面中包含的 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>

最佳答案

Gmail 会删除电子邮件 HTML 的整个标题部分。因此,它还会删除任何 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>

关于c# - 使用 css 发送电子邮件时无法获取 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44711461/

相关文章:

c# - 在 C#.net 中使重叠的图片框透明

c# - 请求卡在 RequestAquireState 模块名称 : Session

css - 检查DIV是否有粘性

css - summernote v0.6.16 上的问题,当我单击链接或图片功能时,模态框在另一个模态框内打开

c# - 使用 Enumerable.OfType<T>() 或 LINQ 查找特定类型的所有子控件

c# - Entity Framework 不支持的类型列表在哪里?

html - 使用隐式宽度和无空格换行防止元素拉伸(stretch)

PHP + MySQL - 获取行并平均分配

html - 按钮向下移动行

javascript - 如何制作显示/隐藏部分的列表?