I'm trying to send calendar invites from my backend server.
Here is the function involved :
fun sendEventInvite(to: String, subject: String, text: String) {
val message: MimeMessage = emailSender.createMimeMessage()
message.setRecipient(Message.RecipientType.TO, InternetAddress(to))
message.subject = subject
val messageBodyText = MimeBodyPart()
messageBodyText.setText(text)
val messageBodyEvent = MimeBodyPart()
messageBodyEvent.dataHandler = ByteArrayDataSource(createEvent(), "text/calendar")
val multiPart = MimeMultipart()
multiPart.addBodyPart(messageBodyEvent)
message.setContent(multiPart)
emailSender.send(message)
}
And here is how I format the ICS file:
fun createEvent(): String{
return "BEGIN:VCALENDAR\n" +
"VERSION:2.0\n" +
"PRODID:-//GRTgaz Corporation//NONSGML Togaz'er//FR\n" +
"METHOD:REQUEST\n" +
"BEGIN:VEVENT\n" +
"UID:d8f5a0777-bf6d-25d2-f14a-52e7fe3df810\n" +
"DTSTAMP:20181119T105044Z\n" +
"ORGANIZER;CN=Baptiste Arnaud:MAILTO:baptiste.arnaud95@gmail.com\n" +
"DTSTART:20181120T150000\n" +
"DTEND:20181120T153000\n" +
"SUMMARY:Description\n" +
"END:VEVENT\n" +
"END:VCALENDAR\n")
}
This file content is supposed to work because it is exactly the same of a working example. So the problem comes from mail headers ? But I'm not sure what's missing.
How it should works:
But it's displayed like this: