为什么 Gmail 会阻止电子邮件中的 CSS?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1555171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 21:09:04  来源:igfitidea点击:

Why is Gmail blocking CSS in emails?

cssgmailhtml-email

提问by MemoryLeak

I used CSS in my email and sent it out.

我在电子邮件中使用了 CSS 并将其发送出去。

When I received the email in Gmail, all the CSS was disabled; however, when I retrieved the email in thunderbird or outlook, everything is OK.

当我在 Gmail 中收到邮件时,所有的 CSS 都被禁用了;但是,当我在 Thunderbird 或 Outlook 中检索电子邮件时,一切正常。

How would I fix this?

我将如何解决这个问题?

回答by o.k.w

Gmail doesn't block CSS totally. It still supports inline style. Why doesnt it support style block, I've no idea. To have a good overview of CSS support in various webmail and email clients, here's a good one. http://www.campaignmonitor.com/css/

Gmail 不会完全阻止 CSS。它仍然支持内联样式。为什么它不支持样式块,我不知道。要对各种网络邮件和电子邮件客户端中的 CSS 支持有一个很好的概述,这里有一个很好的。http://www.campaignmonitor.com/css/

回答by Kashif Ullah

I am answering it too late but this may help someone here. To be able to view your mail as it is in gmail and other email clients, you need inline style for each tag in your html, but writing inline css for each html tag is time consuming, to save your time use the builtin tool

我回答得太晚了,但这可能会帮助这里的人。为了能够像在 gmail 和其他电子邮件客户端中一样查看您的邮件,您需要为 html 中的每个标签设置内联样式,但是为每个 html 标签编写内联 css 非常耗时,为了节省您的时间,请使用内置工具

http://templates.mailchimp.com/resources/inline-css/

Just paste your whole email template and you will get the html document with inline css in each tag. That much easy :)

只需粘贴您的整个电子邮件模板,您就会在每个标签中获得带有内联 css 的 html 文档。这么简单:)

Note: you can have your class and id in class as it is.

注意:您可以按原样在课堂上使用您的班级和 id。

回答by bobince

Stylesheets are one of many, many HTML features that are often blocked by webmail providers.

样式表是经常被网络邮件提供商阻止的众多 HTML 功能之一。

HTML mail is a world of hurtand it's not going to get any better?—?in fact, you can expect it to get worse. Almost every feature of HTML is not supported in somemailer or webmail service. Anything at all modern is a dead loss. And of course there are still the text-only clients.

HTML 邮件是一个充满伤害的世界,它不会变得更好?-?事实上,您可以预期它会变得更糟某些邮件程序或网络邮件服务几乎不支持 HTML 的所有功能。任何现代的东西都是致命的损失。当然,仍然有纯文本客户端。

Unless you have endless spare time to burn uglying up your code and testing every last mailer, forget HTML mail. Just send a text mail with a link to a normal web page where you can be sure everything will work as expected.

除非你有无尽的空闲时间来烧毁你的代码并测试每一个最后的邮件,否则忘记 HTML 邮件。只需发送带有指向普通网页的链接的文本邮件,您就可以确保一切都按预期进行。

回答by NerdFury

If you could embed styles to classes and ids in an email, those could accidentally collide with styles used by gmail to display the application, or on purpose by someone with malicious intentions. In-line styles are local to the tag, and therefor leave gmail styles alone.

如果您可以将样式嵌入电子邮件中的类和 ID,这些样式可能会意外地与 gmail 用于显示应用程序的样式发生冲突,或者被怀有恶意的人故意冲突。内嵌样式是标签的本地样式,因此不要管 gmail 样式。

Google has to protect the user experience that it has created for people.

Google 必须保护它为人们创造的用户体验。

回答by mbear

Another good source of info is the MailChimp EMail Template Reference. I find the Development section particularly useful because it includes information about what CSS GMail does support and how to take advantage of it.

另一个很好的信息来源是MailChimp 电子邮件模板参考。我发现开发部分特别有用,因为它包含有关 CSS GMail 支持什么以及如何利用它的信息。

回答by Mike Wells

I have just been testing this and it does support inline styles, makes the code a bit ugly but you can get around it all.

我刚刚对此进行了测试,它确实支持内联样式,使代码有点难看,但您可以解决所有问题。

Hope that helps.

希望有帮助。

回答by Mike Bethany

If you're using Ruby on Rails and ActionMailer you can use the gem ActionMailer Inline CSS. All you have to do is install the gem and it will automatically inline all the CSS in your mail templates. It literally could not be easier.

如果您使用 Ruby on Rails 和 ActionMailer,则可以使用 gem ActionMailer Inline CSS。您所要做的就是安装 gem,它会自动内联邮件模板中的所有 CSS。从字面上看,这再简单不过了。

ActionMailer Inline CSS on GitHub

GitHub 上的 ActionMailer 内联 CSS

回答by Kevin R

<style type="text/css"></style>

Tags have worked for me, I did have an issue where all my CSS was not working because I missed a ;It was a tedious process but I eventually found it.

标签对我有用,我确实遇到了一个问题,我的所有 CSS 都无法工作,因为我错过了;一个乏味的过程,但我最终找到了它。

At this link#9 from here gave me the initial hint that it may be due to an individual line of CSS.

在此链接中的#9 上给了我最初的提示,这可能是由于单独的 CSS 行造成的。

回答by Rex M

Gmail blocks all external (referenced) assets - stylesheets, images, scripts, etc. This is to protect the privacy of the recipient. You can still include inline styles:

Gmail 会阻止所有外部(引用)资产 - 样式表、图像、脚本等。这是为了保护收件人的隐私。您仍然可以包含内联样式:

<span style="color:red;">Red text</span>