我已经编写了java代码来发送日历邀请。它适用于gmail,thunderbird。客户阅读ics并正确显示邀请。
但是同样的邮件似乎不适用于Microsoft Outlook。 Outlook无法将邮件识别为日历邀请,因此不显示接受,拒绝按钮。
以下是使用的代码段:
MimeMessage message = new MimeMessage(session);
message.addHeaderLine("method=REQUEST");
message.addHeaderLine("charset=UTF-8");
message.addHeaderLine("component=VEVENT");
BodyPart textBodyPart = new MimeBodyPart();
textBodyPart.setContent("Invitation for an event.", "text/plain");
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.addHeader("Content-Class", "urn:content-classes:calendarmessage");
messageBodyPart.addHeader("Content-ID", "calendar_message");
messageBodyPart.setContent(inviteMessage, "text/calendar");
Multipart multipart = new MimeMultipart("alternative");
multipart.addBodyPart(textBodyPart);
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
我发送的ics文件是:
BEGIN:VCALENDAR
VERSION:1.0
PRODID:-//Michael Angstadt//biweekly 0.6.0//EN
METHOD:REQUEST
BEGIN:VEVENT
DTSTAMP:20170123T115919Z
ORGANIZER:mailto:x@y.com
UID:12345678
COMMENT:Event Invitation
DTSTART:20170123T120319Z
SUMMARY;LANGUAGE=en-us:Event Invitation
DURATION:PT30M
ATTENDEE;RSVP=TRUE;ROLE=CHAIR;PARTSTAT=NEEDS-ACTION;CN=XY:mail
to:x.y@gmail.com
END:VEVENT
END:VCALENDAR
在stackoverflow上发现了类似的问题,尝试了上面提到的解决方案,但没有任何帮助。 Multipart email with text and calendar: Outlook doesn't recognize ics
Sending Outlook meeting requests without Outlook?
Java, ICS calendar format not showing time when imported in Outlook or Thunderbird
答案 0 :(得分:1)
按如下所示修改内容类型确实对我有用。
messageBodyPart.setContent(inviteMessage, "text/calendar;method=REQUEST");