当我选择在电子邮件客户端中阻止 HTML 电子邮件时会发生什么?
- 它会从我的电子邮件中删除 HTML 内容吗?
- 它是否在 MIME 内容中查找替代文本部分?
我尝试了 Outlook 2010,它删除了 HTML 内容并仅显示文本。我不确定它是否因为找不到文本内容或 Outlook 只是停止查找文本内容并删除 HTML。
下面是我的代码片段,
//HTML Version
BodyPart htmlBodyPart = new MimeBodyPart();
htmlBodyPart.setContent(htmlContent, "text/html");
//Text Version
BodyPart textBodyPart = new MimeBodyPart();
textBodyPart.setContent(textContent, "text/plain");
Multipart multipart = new MimeMultipart("alternative");
multipart.addBodyPart(textBodyPart); //add text part
multipart.addBodyPart(htmlBodyPart); //add html part
令人惊讶的是,Google 在这件事上没有帮助我。
最佳答案
Outlook 似乎不使用 text/plain 替代方案,并且当配置为以纯文本形式显示邮件时,它会使用转换为纯文本的 text/html 部分。
我在以下链接中找到了该行为的确认:
- http://www.campaignmonitor.com/blog/post/2520/testing-the-plain-text-version
- http://answers.microsoft.com/en-us/office/forum/office_2007-customize/outlook-multipart-text-only-version/41b88569-fa64-e011-8dfc-68b599b31bf5
- http://social.technet.microsoft.com/Forums/en-US/exchangesvrclientslegacy/thread/7bcb49d9-8d2c-4993-8f00-47984a079a63/
- http://www.pcreview.co.uk/forums/text-plain-part-multipart-message-ignored-html-part-converted-instead-outlook-2003-a-t2726684.html
其他(大多数?)电子邮件客户端(例如 Thunderbird)在配置为将消息显示为文本时将显示文本/纯文本替代方案。但是 Outlook 所做的(使用 text/html 部分)似乎并不是一个错误 - 来自维基百科 MIME :
Systems can then choose the "best" representation they are capable of processing; in general, this will be the last part that the system can understand, although other factors may affect this.
显然,还建议在 HTML 和 TEXT 版本中包含类似的内容,以避免被归类为垃圾邮件 - 来自同一维基百科页面:
Anti-spam software eventually caught up on this trick, penalizing messages with very different text in a multipart/alternative message.
因此,我建议构建 text/plain 部分,并将 text/html 部分的内容转换为文本,以便
- 所有配置为将电子邮件显示为文本的电子邮件客户端都以相同的方式显示电子邮件内容
- 被分类为垃圾邮件的概率不会因为内容不同的部分而增加
关于java - 当我在电子邮件客户端中设置阻止 HTML 电子邮件时会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15646292/