To begin, I will set the scenario. I am using the biweekly library to create a VEvent and an ICalendar. Everything is working fine (code below). I can successfully send a calendar invite to Google and the appropriate 'Accept, Decline, Add to Calendar' options are available.
When I send the same message to Outlook, I do not receive the correct invite. The message is formatted in such a way that it expects the recipient to send the invite - not be invited, nor add to his/her calendar.
The framework:
Java - JavaMailSender - Spring Boot - biweekly
The code is operational. The issue in is the difference in which Outlook handles the calendar invite.
Here is the Java code...
@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);
}
}
Here is the 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
Here is the Opened Outlook Email (notice how it is a composed message)...
Here is the Opened Gmail Email...
I have found the documentation to be limited and was hoping somebody may have/is encountered/ecountering the same issue. Thanks for reading.
I did away with the biweekly library...although I feel like the solution would be quite simple and I might revisit the issue. For the record, biweekly is a great library for helping in the creation of VEVENTS and VCALENDARS inside Java.
I resorted back to making the ics manually. This format is completely functional and works with both Gmail and Outlook.