无法使用java mail将richtext内容类型邮件发送到outlook
我正在使用java邮件api向outlook发送邮件。我可以发送纯文本和html内容邮件,但当我将内容类型设置为text/richtext时,我只接收纯文本邮件 有谁能建议如何发送文本邮件?以下是我尝试过的:无法使用java mail将richtext内容类型邮件发送到outlook,java,jakarta-mail,Java,Jakarta Mail,我正在使用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 cli
// 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);
首先-尝试将richtext添加为内容,而不是纯文本:
{\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");
然后,您可能想考虑实际提供一个替代文本,这样您就可以有两个不同的版本
最后,像Mozilla Thunderbird一样,使用电子邮件客户端可以查看收到消息的MIME源代码,这对您有很大帮助 您是否可能对和感到困惑
这是两种不同的格式,与HTML无关。如果您添加了一些richtext格式,则会有所帮助,否则就没有区别。是的,但outlook会在邮件顶部显示内容类型。因此,我们可以轻松识别内容类型。您的文本是纯文本。您看过outlook中的标题了吗?我的意思是,如果我以richtext的形式发送内容类型,则outlook发送的任何内容都应该在邮件顶部的括号中显示内容类型richtext,如消息-(richtext)检查标题。你的客户如何显示它是一个完全不同的故事,我需要复制并粘贴到内容中吗?我已经尝试了上面的例子,也以richtext为例,但它会按原样发送,在标题中,它显示多部分/相关,在邮件顶部,它显示纯文本。我发现了这一点,但如何创建winmail.dat或tnef,请您指导。我尝试了这两种方法,但outlook不显示richtext