【问题标题】:Unable to send richtext content type mail to outlook using java mail无法使用 java 邮件将富文本内容类型的邮件发送到 Outlook
【发布时间】:2016-04-11 23:08:07
【问题描述】:

我正在使用 java 邮件 api 向 Outlook 发送邮件。我可以发送纯文本和 html 内容邮件,但是当我将内容类型设置为 text/richtext 但我只接收纯文本邮件。

任何机构都可以建议如何发送富文本邮件吗?这是我尝试过的:

// the parent or main part if you will
Multipart mainMultipart = new MimeMultipart("related");

// this will hold text and html and tells the client there are 2 versions of the message (html and text). presumably text
// being the alternative to html
Multipart htmlAndTextMultipart = new MimeMultipart("alternative");

// set html
MimeBodyPart htmlBodyPart = new MimeBodyPart();
htmlBodyPart.setContent("Hi", "text/richtext");
htmlAndTextMultipart.addBodyPart(htmlBodyPart);

MimeBodyPart htmlAndTextBodyPart = new MimeBodyPart();
htmlAndTextBodyPart.setContent(htmlAndTextMultipart);
mainMultipart.addBodyPart(htmlAndTextBodyPart);

message.setContent(mainMultipart);

【问题讨论】:

  • 如果您添加一些富文本格式会有所帮助 - 否则差异不存在。
  • 是的,但是 Outlook 在邮件顶部显示内容类型。因此我们可以轻松识别内容类型。
  • 您的文本纯文本。你看过outlook中的标题吗?
  • 我的意思是,如果我将内容类型作为富文本发送,无论我发送什么,Outlook 都应该在邮件顶部的括号中显示内容类型富文本,例如 Message-(Rich text)
  • 检查标题。您的客户如何展示是完全不同的故事

标签: java jakarta-mail


【解决方案1】:

您可能对text/richtexttext/rtf 感到困惑

这是两种不同的格式,与 HTML 无关。

【讨论】:

  • 我都试过了,但是outlook没有显示富文本
【解决方案2】:

首先 - 尝试将富文本添加为​​内容,而不是纯文本:

{\rtf1\ansi\deff0 {\fonttbl {\f0 Courier;}}
{\colortbl;\red0\green0\blue0;\red255\green0\blue0;}
This line is the default color\line
\cf2
\tab This line is red and has a tab before it\line
\cf1
\page This line is the default color and the first line on page 2
}

在代码中可能看起来像

htmlBodyPart.setContent("{\\rtf1\\ansi\\deff0 {\\fonttbl {\\f0 Courier;}}\r\n" +
"{\\colortbl;\\red0\\green0\\blue0;\\red255\\green0\\blue0;}\r\n" +
"This line is the default color\\line\r\n" +
"\\cf2\r\n" +
"\\tab This line is red and has a tab before it\\line\r\n" +
"\\cf1\r\n" +
"\\page This line is the default color and the first line on page 2\r\n" +
"}", "text/richtext");

那么您可能想要考虑实际提供替代文本 - 这样您就可以有两个不同的版本。

最后,使用允许您查看收到消息的 MIME 源的电子邮件客户端很有帮助 - 就像 Mozilla Thunderbird 所做的那样。

【讨论】:

  • 我需要复制并粘贴到内容中吗?
  • 我已经在上面尝试过,也以富文本为例,但它按原样发送,在标题中显示多部分/相关,在邮件顶部显示纯文本
  • 我找到了这个stackoverflow.com/questions/2109563/…,但是如何创建winmail.dat 或tnef 请您指导一下。
猜你喜欢
  • 1970-01-01
  • 2010-10-13
  • 1970-01-01
  • 1970-01-01
  • 2017-08-29
  • 2014-04-14
  • 2016-11-10
  • 2020-04-14
  • 2014-04-06
相关资源
最近更新 更多