calendar events with java e-mail

I have made a .ics file to send from org.apache.commons.mail.MultiPartEmail but the result is different on each email server;


Example:

When sending to a G-Mail Address, the receiver identifies the .ics file like an event and shows the details of the event in the body of the mail.

At Yahoo, it identifies the event but doesn't show the details.

In the Microsoft mail server (hotmail, outlook), .ics file appears like a plaintext in the body of mail and doesn't get recognized as an event.


I really don't know how I can make the Microsoft mail server recognize the event and show the details and the button to add in the calendar.

This is the .ics code:

BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
PRODID:LBstation
BEGIN:VEVENT
UID:1e89d5a5-09c3-477c-9dd7-b9af39e514b2
DTSTAMP:20160506T143307Z
SUMMARY:Test ICS
DTSTART:20160529T130000Z
DTEND:20160529T140000Z
ATTENDEE;CUTYPE=INDIVIDUAL;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;ROLE=ATTENDEE;CN=Leonardo Outlook:mailto:[email protected]
ATTENDEE;CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED;RSVP=TRUE;ROLE=ORGANIZER;CN=Leonardo Peixoto:mailto:[email protected]
SEQUENCE:0
ORGANIZER;CN=Leonardo Bruno Peixoto:mailto:[email protected]
CREATED:20160506T143307Z
LAST-MODIFIED:20160506T143307Z
DESCRIPTION:Test ics
TRANSP:OPAQUE
STATUS:CONFIRMED
LOCATION:
END:VEVENT
END:VCALENDAR

And this is the code:

MimeMultipart mmp = new MimeMultipart("mixed");

    MimeMultipart mmpa = new MimeMultipart("alternative");

    MimeBodyPart plainPart = new MimeBodyPart();
    plainPart.setHeader("Content-Type", "text/plain; charset=UTF-8; format=flowed; delsp=yes");
    plainPart.setHeader("Content-Transfer-Encoding", "base64");
    ByteArrayDataSource dsPlain = new ByteArrayDataSource("","text/plain;method=REQUEST");
    DataHandler dhPlain = new DataHandler(dsPlain);
    plainPart.setDataHandler(dhPlain);
    mmpa.addBodyPart(plainPart);

    MimeBodyPart calendarPart = new MimeBodyPart();
    calendarPart.setHeader("Content-Type", "text/calendar; charset=UTF-8; method=REQUEST");
    calendarPart.setHeader("Content-Transfer-Encoding", "7bit");
    ByteArrayDataSource dsCalendario = new ByteArrayDataSource(str,"text/calendar;method=REQUEST");
    DataHandler dhCalendario = new DataHandler(dsCalendario);
    calendarPart.setDataHandler(dhCalendario);
    mmpa.addBodyPart(calendarPart);

    MimeBodyPart htmlAndTextBodyPart = new MimeBodyPart();
    htmlAndTextBodyPart.setContent(mmpa);
    mmp.addBodyPart(htmlAndTextBodyPart);


    email.addPart(mmp);

Upvotes: 1

Views: 2664

Answers (1)

solved! The problem was that was creating the mimepart for MultiPartEmail when put in a SimpleEmail worked perfectly.

SimpleEmail email = new SimpleEmail();

MimeMultipart mmpa = new MimeMultipart("alternative");

//Calendar
MimeBodyPart calendarPart = new MimeBodyPart();
calendarPart.setHeader("Content-Type", "text/calendar; charset=UTF-8; method=REQUEST");
ByteArrayDataSource dsCalendario = new ByteArrayDataSource(str,"text/calendar;method=REQUEST");
DataHandler dhCalendario = new DataHandler(dsCalendario);
calendarPart.setDataHandler(dhCalendario);
mmpa.addBodyPart(calendarPart);

email.setContent(mmpa);

Upvotes: 2

Related Questions