我正在try 通过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页上的外观:

enter image description here

当我将邮箱发送到Outlook时,屏幕如下所示:

enter image description here

公司名称和城市名称都会在图标下方移动.我try 将FLEX Direction更改为Row,但没有解决任何问题.我也try 了Outlook的zoom 设置,设置为100%.以下是发送邮箱的C#代码:

SmtpClient客户端=new SmtpClient();

        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中丢失,我们将不胜感激.我还try 使用这样的表标记:

 <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>

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

enter image description here

我的问题与HTML样式无关,它与Outlook有关.为什么我看不到Outlook邮箱中的更改.内森回答了我的问题.

推荐答案

Outlook使用MS Word来呈现邮箱,而不是网络标准解析器.

Div、flex以及几乎所有的东西都不能正常工作:https://www.caniemail.com/clients/outlook/#windows

为此,您需要使用表格布局.并且内嵌你所有的风格--不要使用<style>块.

Csharp相关问答推荐

HttpContext. RequestAborted当Android APP失go 连接时未取消

如何在Reflection. Emit中使用具有运行时定义的类型参数的泛型类型

并行令牌更新

FileStream. FlushAsync()是否确保文件被写入磁盘?

. NET 8控制台应用程序DI错误无法解析Microsoft. Extension. Logging. ILoggerFactory类型的服务'''

模型绑定RazorPage表单

有没有办法使.NET 6应用程序在特定的.NET 6运行时版本上运行

如何使用C#中的主构造函数功能使用多个构造函数?

Docker Container中的HttpRequest后地址不可用

在不添加不必要的尾随零的情况下本地化浮点型?

用于管理System.Text.Json中的多态反序列化的自定义TypeInfoResolver

正确处理嵌套的本机集合

自定义列表按字符串的部分排序

在implementationFactory中避免循环依赖

在C#中,是否有与变量DISARD对应的C++类似功能?

如何从非异步任务中正确返回TypeResult

将字符串类型日期输入(yyyy-mm-ddthh:mm:ss)转换为MM/dd/yyyy格式

Azure函数正在返回值列表,但该列表在Chrome中显示为空

仅在ASP.NETCore应用程序中的附加单独端口上公开一组终结点

在Visual Studio 2022中查找Xamarin模板时遇到问题