【问题标题】:Java: ics not read in outlookJava:不能在 Outlook 中读取 ics
【发布时间】:2017-06-12 22:39:47
【问题描述】:

我已经编写了 java 代码来发送日历邀请。它适用于 gmail,雷鸟。客户阅读 ics 并正确显示邀请。

但同一封邮件似乎无法在 Microsoft Outlook 上运行。 Outlook 不会将该邮件识别为日历邀请,因此不会显示接受、拒绝按钮。

下面是sn-p使用的代码:

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

【问题讨论】:

  • 您是否尝试将原始 Outlook 邀请导出到 ICS 并检查其属性?
  • 是的,也这样做了。没用。还使用谷歌日历手动创建了一个活动,并将邀请发送到在 Outlook 上配置的电子邮件。 Outlook 可以识别该邀请,以便在代码中对 gmail ics 进行硬编码并尝试过,但这也不起作用。

标签: java email outlook calendar


【解决方案1】:

在我的案例中添加以下代码行是一个难题(在答案 https://stackoverflow.com/a/67521336/14972917 中找到):

final MimetypesFileTypeMap mimetypes = (MimetypesFileTypeMap) MimetypesFileTypeMap.getDefaultFileTypeMap();
mimetypes.addMimeTypes("text/calendar ics ICS");
final MailcapCommandMap mailcap = (MailcapCommandMap) MailcapCommandMap.getDefaultCommandMap();
mailcap.addMailcap("text/calendar;; x-java-content-handler=com.sun.mail.handlers.text_plain");

【讨论】:

    【解决方案2】:

    如下修改内容类型对我有用。

    messageBodyPart.setContent(inviteMessage, "text/calendar;method=REQUEST");
    

    【讨论】:

      猜你喜欢
      • 2021-09-22
      • 1970-01-01
      • 1970-01-01
      • 2011-08-05
      • 1970-01-01
      • 2014-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多