电子邮件中是否支持 JavaScript?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3054315/
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
Is JavaScript supported in an email message?
提问by senthil
Is JavaScript supported in an email message?
电子邮件中是否支持 JavaScript?
回答by MatthewMartin
http://en.wikipedia.org/wiki/Comparison_of_e-mail_clients
http://en.wikipedia.org/wiki/Comparison_of_e-mail_clients
Old clients, such as Lotus Notes, Mozilla Thunderbird, Outlook Express, and Windows Live Mail all seem to have supported some sort of JavaScript execution. Nothing else does.
旧客户端,例如 Lotus Notes、Mozilla Thunderbird、Outlook Express 和 Windows Live Mail,似乎都支持某种 JavaScript 执行。其他什么都不做。
It seems like a bad idea security-wise, so I would expect this to be a feature that won't always be around, even in these clients.
从安全角度来看,这似乎是一个坏主意,所以我希望这是一个不会一直存在的功能,即使在这些客户端中也是如此。
回答by Robert Morewood
Other answerers have suggested that the answer is "No."
其他回答者建议答案是“否”。
On the other hand, an html attachment will probably get opened in an environment that runs Javascript.
另一方面,html 附件可能会在运行 Javascript 的环境中打开。
EDIT: It was suggested that I haven't properly answered the question so here goes a more complete effort.
编辑:有人建议我没有正确回答这个问题,所以这里有一个更完整的努力。
Summary: I would expect that many or most users receiving an html-formatted email containing embedded Javascript will see it run and have run tests to confirm that this is true in some environments. But Javascript WILL be blocked for some users.
简介: 我希望收到包含嵌入式 Javascript 的 html 格式电子邮件的许多或大多数用户会看到它运行并运行测试以确认这在某些环境中是正确的。但是 Javascript 将被某些用户阻止。
The protocols (specifically RFC2854) explicitly address scripting (within the text/html message body type) with the statement that:
协议(特别是 RFC2854)使用以下语句明确解决脚本编写(在 text/html 消息正文类型内):
In addition, the introduction of scripting languages and interactive capabilities in HTML 4.0 introduced a number of security risks associated with the automatic execution of programs written by the sender but interpreted by the recipient. User agents executing such scripts or programs must be extremely careful to insure that untrusted software is executed in a protected environment.
此外,HTML 4.0 中脚本语言和交互功能的引入引入了许多与自动执行由发送者编写但由接收者解释的程序相关的安全风险。执行此类脚本或程序的用户代理必须非常小心,以确保不受信任的软件在受保护的环境中执行。
So the protocols do support Javascript, but which user agents do?
所以这些协议确实支持 Javascript,但是哪些用户代理呢?
My (ancient) email reader uses a table to specify which viewer software to use for each mimetype, diverting html content to my favorite web browser. Almost all current web browsers support Javascript (and some issue dire warnings when you try to turn it off!) Do modern email agents include internal html interpreters and, if so, is the javascript turned on or off? I've checked documentation on Thunderbird and find that javascript seems to be turned on by default but can be turned off: http://codeverge.com/mozilla.support.thunderbird/simple-html-tags-reference-docume/2030160
我的(古老的)电子邮件阅读器使用一个表格来指定每个 mimetype 使用哪个查看器软件,将 html 内容转移到我最喜欢的 web 浏览器。几乎所有当前的 Web 浏览器都支持 Javascript(并且在您尝试关闭它时会发出可怕的警告!)现代电子邮件代理是否包含内部 html 解释器,如果是,javascript 是打开还是关闭?我检查了有关 Thunderbird 的文档,发现 javascript 似乎默认打开但可以关闭:http: //codeverge.com/mozilla.support.thunderbird/simple-html-tags-reference-docume/2030160
I have noticed that some (?many?) users now access their email from a browser directly (webmail is one such platform) rather than running separate email software. All such platforms which I have tested so far do run any Javascript embedded in the html of the email message. However some such environments, depending on user security settings, do not automatically fetch external links (Javascript or pictures or other) and so can only run external Javascript from a file which is included as an attachment to the message. The same would be true of any offline email reader on a device without a current internet connection.
我注意到一些(?很多?)用户现在直接从浏览器访问他们的电子邮件(网络邮件就是一个这样的平台),而不是运行单独的电子邮件软件。到目前为止,我测试过的所有此类平台都运行嵌入在电子邮件消息的 html 中的任何 Javascript。然而,根据用户安全设置,某些此类环境不会自动获取外部链接(Javascript 或图片或其他),因此只能从作为邮件附件包含的文件运行外部 Javascript。对于没有当前互联网连接的设备上的任何离线电子邮件阅读器,情况也是如此。
The above applies to javascript embedded in the main message part of the email body. One can also have html explicitly given as an "attachment", which if saved and then opened would be displayed in a web browser, wherein Javascript is available with very high likelyhood. Therefore, one might included a second copy of the javascript enabled email as an html attachement with an alternative text/plain main body and/or tag in the main text/html directing the user to the attachment.
以上适用于嵌入在电子邮件正文的主要消息部分中的 javascript。还可以将 html 明确指定为“附件”,如果保存然后打开,将显示在 Web 浏览器中,其中 Javascript 很有可能可用。因此,可以将启用 javascript 的电子邮件的第二个副本作为 html 附件包含在主文本/html 中,并在主文本/html 中将用户定向到附件。
I've been thinking about this because some of my acquaintances insist on sending me "email greeting cards" which consist of a text message directing me to a link which I've found so unsatisfactory that I refuse to even consider loading it just on principle. I have written and sent email greeting cards with interactive graphics and music and even games using embedded javascript and been satisfied with the result.
我一直在考虑这个,因为我的一些熟人坚持给我发送“电子邮件贺卡”,其中包含一条短信,将我定向到一个链接,我觉得这个链接很不满意,我什至拒绝考虑加载它只是原则上. 我已经使用嵌入式 javascript 编写并发送了带有交互式图形和音乐甚至游戏的电子邮件贺卡,并且对结果感到满意。
Therefore, I maintain that the correct answer is "Yes" both on the grounds that the protocols specifically address scripting and on the grounds that all the email agents I personally use ran the Javascript in my test emails.
因此,我认为正确的答案是“是”,因为协议专门针对脚本编写,而且我个人使用的所有电子邮件代理都在我的测试电子邮件中运行了 Javascript。
回答by jsight
No, generally speaking email readers do not allow javascript.
不,一般来说电子邮件阅读器不允许使用 javascript。
回答by Ketan R
Short answer
简答
No
不
Descriptive answer
描述性答案
It depends. But the email is not guaranteed to behave in the way you want it to. Different email clients handle JS differently. Most of the newer email clients do not support any of it since it is potentially very dangerous to support script execution in a desktop application which contains so much of your personal info.
这取决于。但不能保证电子邮件按您希望的方式运行。不同的电子邮件客户端以不同的方式处理 JS。大多数较新的电子邮件客户端都不支持其中任何一项,因为在包含大量个人信息的桌面应用程序中支持脚本执行可能非常危险。
I had a use case where I needed to use JS in an email. I tried out on the web client of outlook and desktop client as well, and it turns out outlook just wipes out the script part of your HTML email. There might be some other email client which does support JS execution, but given that you cannot control the client where your email would be viewed in the client machine, it's not a good idea to embed any scripts in the HTML email.
我有一个用例,我需要在电子邮件中使用 JS。我也在 Outlook 和桌面客户端的 Web 客户端上进行了尝试,结果 Outlook 只是清除了 HTML 电子邮件的脚本部分。可能还有其他一些支持 JS 执行的电子邮件客户端,但鉴于您无法控制在客户端计算机中查看电子邮件的客户端,因此在 HTML 电子邮件中嵌入任何脚本并不是一个好主意。
Its advised to keep your HTML email as simple as possible, no JS, and the least CSS you can do with (because, again, different email clients have varying support for CSS as well) eg: outlook's web client was not even recognizing an HTML button tag in the email. I had to use an anchor tag and some CSS on top of it to mimic the display of a button.
建议让您的 HTML 电子邮件尽可能简单,不要使用 JS,并且可以使用最少的 CSS(因为,同样,不同的电子邮件客户端对 CSS 的支持也不同)例如:outlook 的 Web 客户端甚至无法识别 HTML电子邮件中的按钮标签。我不得不使用锚标记和一些 CSS 来模拟按钮的显示。
Bottom line - don't rely on Javascript when working with HTML email content.
底线 - 在处理 HTML 电子邮件内容时不要依赖 Javascript。
回答by Sam152
You aren't going to get executable JavaScript onto a server and into a mail client. But emails DO support links, you can always link to your content within an email.
您不会将可执行的 JavaScript 放到服务器和邮件客户端中。但是电子邮件确实支持链接,您始终可以在电子邮件中链接到您的内容。
回答by Mervyn
For most mail clients, no.
对于大多数邮件客户端,没有。
回答by Ed B
It may be, but mail clients won't read it & mail servers may reject it. So leave it out.
可能是,但邮件客户端不会读取它,邮件服务器可能会拒绝它。所以别管它。
回答by Neil Knight
Javascript is not supported in emails.
电子邮件不支持 Javascript。
回答by Mark Antony Agius
You can view an email with JavaScript working with Windows Live Mail, but can't add JavaScript to a new email you wish to send. JavaScript also works with saved .eml files. Mozilla Thunderbird version 60.7.0 can't view or add JavaScript. (If you save an eml file with Thunderbird, the code will work if file is then loaded with Live Mail) You can send an email with JavaScript using PHP code. Some email websites may support it, but the few I used don't. (AOL, uk2.net, GMail)
您可以使用 JavaScript 和 Windows Live Mail 查看电子邮件,但不能将 JavaScript 添加到您要发送的新电子邮件中。JavaScript 也适用于保存的 .eml 文件。Mozilla Thunderbird 60.7.0 版无法查看或添加 JavaScript。(如果你用 Thunderbird 保存了一个 eml 文件,如果文件然后用 Live Mail 加载,代码将起作用)你可以使用 PHP 代码用 JavaScript 发送电子邮件。一些电子邮件网站可能支持它,但我使用的少数网站不支持。(美国在线、uk2.net、GMail)

