使用 System.Net.Mail 时格式化电子邮件的最佳方法是什么

发布于 2024-07-10 07:25:34 字数 223 浏览 5 评论 0原文

您好,我正在使用 System.Net.Mail 发送一些 HTML 格式的电子邮件。

将 css 插入电子邮件的正确方法是什么?

我知道我可以对每个项目应用格式,但我宁愿使用样式表。

编辑 我应该提到这是一个内部应用程序,我预计 99% 的用户会使用 Outlook 或其他客户端,但绝不会使用 hotmail 或 gmail 等。

Hi I'm using System.Net.Mail to send some HTML formatted emails.

What is the correct method for inserting css into the email message?

I know I can apply formatting to each item, but I'ld rather use style sheets..

EDIT
I should have mentioned that this is for an internal application, and I expect 99% of users to be using Outlook or other client, but never hotmail or gmail etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

彩扇题诗 2024-07-17 07:25:34

我一直发现严格使用 HTML 3.0 兼容标签和格式最适合所有电子邮件阅读器和提供商。

不过,这里有一篇电子邮件中的CSS文章可以回答您的问题,您将找到 css 问题的解决方案。

I've always found that strictly using HTML 3.0 compatible tags and formatting works best for all email readers and providers.

nevertheless here is a CSS in Email article that may answer your question, you will find solutions to your css problems.

只有影子陪我不离不弃 2024-07-17 07:25:34

电子邮件客户端不以统一的方式使用CSS,因此很难使用CSS。 本文可以提供帮助 - http://www.alistapart.com/articles/cssemail/

The email clients don't use CSS in a uniform way so it's difficult to use CSS. This article can help - http://www.alistapart.com/articles/cssemail/

飘然心甜 2024-07-17 07:25:34

您可以将样式保留在普通的 CSS 文件中,并使用 File.ReadAllText 并将它们插入到 HTML 信件模板中

string letter = File.ReadAllText(Request.PhysicalApplicationPath + "letter.html");
string style = File.ReadAllText(Request.PhysicalApplicationPath + "style.css");

MailMessage message = new MailMessage();
message.Body = letter.Replace("{STYLE}", style);

信件模板应在适当的位置包含 {STYLE}

<head>
    <title></title>
    <style type="text/css">
        {STYLE}
    </style>
</head>
<body>

You could keep styles in a normal CSS file, load them with File.ReadAllText and insert them to a HTML letter template

string letter = File.ReadAllText(Request.PhysicalApplicationPath + "letter.html");
string style = File.ReadAllText(Request.PhysicalApplicationPath + "style.css");

MailMessage message = new MailMessage();
message.Body = letter.Replace("{STYLE}", style);

The letter template should contain {STYLE} in appropriate place

<head>
    <title></title>
    <style type="text/css">
        {STYLE}
    </style>
</head>
<body>
风吹雪碎 2024-07-17 07:25:34

此参考是我发现的关于 CSS 的最佳参考资料在电子邮件中。

不过说实话,CSS 支持非常不稳定,您最好按照上一张海报所说的那样坚持使用基本的 HTML(是的,这意味着使用过时的字体标签等)。 特别是当你提到 Outlook(至少是最新版本)时,它是糟糕的 CSS 支持的最糟糕的罪魁祸首。

This reference is the best one I've found to see what works in what when it comes to CSS in emails.

To be honest though, CSS support is so, so flaky that you're better off doing as the previous poster says and sticking to basic HTML (and yes, that means using outdated font tags etc). Especially as you mention Outlook and that (at least the latest version) is the worst culprit when it comes to terrible CSS support.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文