我正在开发一个ics发送器功能。但我在使用office 365和outlook时遇到一些问题。当我将ics文件发送到google mail时,我没有遇到任何问题。我的事件会出现在gmail中。但当我发送到outlook或Office365时,我的约会没有出现,但它在电子邮件附件( ATT00001.ics)中。这是发送邮件的代码
private void generateIcal(MimeMessage message) throws MessagingException, IOException {
message.addHeaderLine("method=REQUEST");
message.addHeaderLine("charset=UTF-8");
message.addHeaderLine("component=VEVENT");
message.setFrom(new InternetAddress(from));
message.setSubject(subj,"UTF-8");
StringBuffer sb = new StringBuffer();
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setHeader("Content-Class", "urn:content-classes:calendarmessage");
messageBodyPart.setHeader("Content-ID", "calendar_message");
messageBodyPart.setDataHandler(new DataHandler(
new ByteArrayDataSource(txt, "text/calendar;charset=utf-8")));//very important
// Create a Multipart
Multipart multipart = new MimeMultipart();
// Add part one
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
}
这将生成ics文件
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//TELELANGUE//NONSGML v1.0//EN
BEGIN:VEVENT
DTSTART:20180714T170000Z
DTEND:20180715T035900Z
SUMMARY:Fête à la Bastille
END:VEVENT
END:VCALENDAR
发布于 2018-10-31 06:47:31
感谢您的回复
最后,我找到了解决方案。看起来,我们需要在BodyPart中设置“方法”和“名称”参数。
MessageBodyPart.setDataHandler(new DataHandler(
new ByteArrayDataSource(buffer.toString(), "text/calendar;method=REQUEST;name=\"meeting.ics\"")));
发布于 2018-09-26 11:00:17
1)解析ics。文件并将其设置为“收件箱”中的事件,以便您无需打开附件即可读取事件信息。
2)添加交互性,以便您可以直接接受/拒绝收件箱中的邀请,甚至不需要打开ics文件。(这就是Gmail现在所拥有的)。
有关更多信息,请参阅以下链接:
https://stackoverflow.com/questions/52493873
复制相似问题