css HTML页面的格式丢失在Outlook电子邮件

kq0g1dla  于 2023-08-09  发布在  其他
关注(0)|答案(1)|浏览(140)

我试图通过C#代码发送HTML邮件。一切正常。我可以发送带有徽标和图标的电子邮件。唯一的问题,我面临的是,格式的标题丢失时,我发送电子邮件到Outlook.下面是我的代码:

<div class="container">
        <div class="logo">
          
            <img src="Images/delete.png" alt="RAC" width="80" height="80" />
           
        </div>
        <div class="names">
      
            <div class="name1">This is City Name</div>
            <div class="name2">This is company Name</div>
        </div>
    </div>

字符串
这是样式表:

<style>

        .container {
            display: flex;
            align-items: center;
            padding: 10px;
            background-color: #335970;
            width:100%;
        }

        .logo {
            margin-right: 10px;
        
        }

        .names {
            display: flex;
            flex-direction: column;
        }

        .name1 {
            font-size: 25px;
            color: #e9c46a;
           
        }

        .name2 {
            font-size: 25px;
            color: white;
        }
    </style>


下面是HTML页面上的屏幕:
x1c 0d1x的数据
当我发送电子邮件到Outlook然后屏幕看起来像这样:



公司名称和城市名称都移动到图标下方。我试着将Flex方向更改为Row,但这并没有解决任何问题。我也尝试了outlook缩放设置,它被设置为100%。这是发送电子邮件的C#代码:
number.new number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. number. n

client.Credentials = new NetworkCredential("test", EmailPass);
        client.Port = 200;
        client.EnableSsl = true;
        client.Host = "smtp.office365.com";
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        
         MailMessage mail = new MailMessage();
       
        mail.IsBodyHtml = true;
        mail.From = test;

        mail.To.Add(new MailAddress("t@t.com"));
        mail.Subject = "test";
        using(StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplate.html")))
        {
            body = reader.ReadToEnd();
        }

        mail.Body = body;

        client.Send(mail);


任何帮助为什么标题的格式丢失在HTML将是高度赞赏。我也试着使用table tag,像这样:

<table style="background-color: #335970;width:100%;padding:10px">
        <tr>
            <td rowspan="3">
                <img src="Images/delete.png" height="80" width="80" />
            </td>
        </tr>
        <tr>
            <td class="name1">This is City Name</td>
        </tr>
        <tr>
            <td class="name2">This is company Name</td>
        </tr>
    </table>


这样,图像和文本之间就有了巨大的空间。请看下面的截图:



我的问题与HTML样式无关,它与Outlook有关。为什么我看不到Outlook电子邮件的变化。内森回答了我的问题。

e37o9pze

e37o9pze1#

Outlook使用MS Word来呈现电子邮件,而不是Web标准解析器。
div、flex和几乎所有的东西都不起作用:https://www.caniemail.com/clients/outlook/#windows
您需要为此使用表布局。并内联所有样式-不要使用<style>块。

相关问题