簡體   English   中英

無法使用Java郵件將RTF內容類型郵件發送到Outlook

[英]Unable to send richtext content type mail to outlook using java mail

我正在使用Java Mail 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);

您可能會在text / richtexttext / rtf之間感到困惑

這些是2種不同的格式,與HTML無關。

首先-嘗試添加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");

然后,您可能需要考慮實際提供替代文本-這樣您可以有兩個不同的版本。

最后,使用電子郵件客戶端可以使您查看接收到的郵件的MIME源,這很有幫助-就像Mozilla Thunderbird一樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM