首先,我將設置場景。我正在使用雙週庫創建一個VEvent和一個ICalendar。一切工作正常(下面的代碼)。我可以成功向Google發送日曆邀請,並提供相應的「接受,拒絕,添加到日曆」選項。Outlook電子郵件和ICS格式 - 奇怪的行爲
當我向Outlook發送相同的郵件時,我沒有收到正確的邀請。郵件的格式要求收件人發送邀請 - 不會被邀請,也不會添加到他/她的日曆中。
框架:
的Java - JavaMailSender - 彈簧引導 - 雙週
的代碼運行。問題在於Outlook處理日曆邀請的區別。
這裏是Java代碼...
@Service
public class CalendarEvent {
private JavaMailSender javaMailSender;
@Autowired
public CalendarEvent(JavaMailSender javaMailSender) {
this.javaMailSender = javaMailSender;
}
public void createCal() throws MessagingException, ParseException, IOException {
ICalendar ical = new ICalendar();
VEvent event = new VEvent();
Attendee attendee = new Attendee("Juniper", "[email protected]");
attendee.setRsvp(true);
attendee.setRole(Role.ATTENDEE);
attendee.setParticipationStatus(ParticipationStatus.NEEDS_ACTION);
attendee.setParticipationLevel(ParticipationLevel.REQUIRED);
event.addAttendee(attendee);
event.setSummary("hello");
DateTime dt = new DateTime(2016, 12, 28, 12, 0);
DateTime et = new DateTime(2016, 12, 28, 13, 30);
Date starts = (Date) dt.toDate();
Date ends = (Date) et.toDate();
DateStart thisStart = new DateStart(starts, true);
DateEnd dateEnd = new DateEnd(ends, true);
event.setDateStart(thisStart);
event.setDateEnd(dateEnd);
Duration reminder = new Duration.Builder().minutes(15).build();
Trigger trigger = new Trigger(reminder, Related.START);
Action action = new Action("DISPLAY");
VAlarm valarm = new VAlarm(action, trigger);
event.addAlarm(valarm);
Duration duration = new Duration.Builder().hours(1).build();
event.setDuration(duration);
event.setUid("555xxx");
event.setOrganizer("[email protected]");
event.setLocation("Small");
ical.addEvent(event);
String str = Biweekly.write(ical).go();
MimeMessage message = javaMailSender.createMimeMessage();
message.addHeaderLine("charset=UTF-8");
message.addHeaderLine("component=VEVENT");
message.addHeaderLine("method=REQUEST");
message.setFrom("[email protected]");
message.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
message.setSubject("You're Invited to a Meeting");
// 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(str, "text/calendar")));// very important
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
javaMailSender.send(message);
}
}
這裏是ICS ...
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Michael Angstadt//biweekly 0.6.0//EN BEGIN:VEVENT
DTSTAMP:20161223T203840Z ATTENDEE;RSVP=TRUE;ROLE=REQ-
PARTICIPANT;PARTSTAT=NEEDS-ACTION;CN=Juniper:mail
to:[email protected]
SUMMARY:hello
DTSTART:20161228T170000Z
DTEND:20161228T183000Z
DURATION:PT1H
UID:555****
ORGANIZER:mailto:[email protected]
LOCATION:Small
BEGIN:VALARM
ACTION:DISPLAY
TRIGGER;RELATED=START:PT15M
END:VALARM
END:VEVENT
END:VCALENDAR
這裏是打開Outlook電子郵件(注意它是如何構成的信息)...
這裏是開啓Gmail電子郵件...
我發現的文件是有限的,希望有人可以有/遇到/ ecountering相同問題。謝謝閱讀。
是你的展望地址與ics文件中的組織者相同嗎?這可能是一個問題 – adekcz
你是對的,那會造成問題。但是,這不是我所面臨的問題。我回到了創建.ics的手動方式,併發布了下面的代碼。適用於Gmail和Outlook(我會想象其他人)。 – ClickerTweeker