Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outlook and office 365 don't recognize ICS file

I'm developping a ics sender functionnality. But i have some trouble with office 365 and outlook. When i sent the ics file to google mail, i don't have any problem. My event appear in the gmail. But when i send to outlook or office 365, my appointment didn't appear but it was in the email attachment ( ATT00001.ics). This is the code send the mail

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);
    }

And this generate the ics file

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
like image 943
YellowStar22 Avatar asked Dec 04 '25 12:12

YellowStar22


1 Answers

Thanks for your reply

Finally, I found the solution. Looks like, we need to set "method" and "name" parameters into the BodyPart.

MessageBodyPart.setDataHandler(new DataHandler(
                    new ByteArrayDataSource(buffer.toString(), "text/calendar;method=REQUEST;name=\"meeting.ics\"")));
like image 184
YellowStar22 Avatar answered Dec 07 '25 03:12

YellowStar22



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!