bbottema/simple-java-mail

Add support for Calendar events (iCalendar vEvent)

sven-geisenhainer opened this issue · 7 comments

Hi and thanks a lot for this great library!

My feature request: I would like to use Simple Java Mail to send calendar invitations, which have to smoothly integrate with Gmail/Google calendar and MS Outlook but should also get properly displayed in any ordinary client. This means I have to create multipart/alternative messages consisting of 3! alternatives: text/plain, text/html and text/calendar - at least MS Outlook is sending such invitations. Simply adding the ICS as attachment does not work with Outlook.

I found no way how to do this with Simple Java Mail, e.g. there is no setTextVCalendar() or addCustomText(String text, String mimeType).

What do you think?

Hi @sven-mvolution, that's a good point! I will think about a proper solution.

I've been trying to create a MimeMessage by hand with an ical event in it using ical4j, but I've been unable to get gMail or Outlook to cooperate with me. It keeps seeing it as a simple attachment.

I'll keep playing around.

Hi @bbottema - thanks for further investigating and considering this a useful enhancement!
Meanwhile I've locally changed your lib to suit my needs as follows - but of course still waiting for the "official" support ;)

  • Add support for a optional text/calendar alternative
  • Use 2051 test port and made unit test work
    See the attached patch file (diff against 5.0.3)
    calendar-alternative.patch.txt

Some how Simple Java Mail manages the bodyparts better than when I do it manually :D

It works in Outlook 365 for me, but gMail still refused and only displays it as an attachment. I wonder if it even still works at all in gMail.

Implemented for the 6.0.0 release.

Usage is simple:

// Create a Calendar with something like ical4j
Calendar icsCalendar = new Calendar();
icsCalendar.getProperties().add(new ProdId("-//Events Calendar//iCal4j 1.0//EN"));
icsCalendar.getProperties().add(Version.VERSION_2_0);

(..) // add attendees, organizer, end/start date and whatever else you need

// Produce calendar string
ByteArrayOutputStream bOutStream = new ByteArrayOutputStream();
new CalendarOutputter().output(icsCalendar, bOutStream);
String yourICalEventString = bOutStream.toString("UTF-8")

// Let Simple Java Mail handle the rest
currentEmailBuilder
    .withCalendarText(CalendarMethod.REQUEST, yourICalEventString)

Thanks for the help @sven-mvolution!

Released in 6.0.0-rc1.

6.0.0 has released as well, finally.