I am trying to send an E-Mail with an open Event to be included in a private calendar. I brought it to work using the Request-Method, but this was not exactly the behaviour I wanted. I do not want the recipients to answer the "invitation" when including the event in their calendars. I found that out I need to use the Publish-Method instead, but now my code is not working anymore. I needed to delete the Attendee-Property, which makes sense, as the event is public and everyone can include it in their private calendars. But once I do this, I get an E-Mail without Accept/Decline etc. Buttons, but instead I get an E-Mail with all the information but also including the note that I still have to send the E-Mail to the recipients. I am using the net.fortuna.ical4j-library to create the Ical-events, here is my code:
final Calendar calendar = new Calendar();
final PropertyList properties = calendar.getProperties();
properties.add(new ProdId("-//my ProdId"));
properties.add(Version.VERSION_2_0);
properties.add(CalScale.GREGORIAN);
properties.add(Method.PUBLISH);
final Date startDate = new Date(TimeFormats.DATE_8.format(recordAttr.get(ATTR_START_DATE)));
// let it last exactly one day to get an all-day event
final Date endDate = new Date(Date.from(LocalDateTime.from(startDate.toInstant().atZone(ZoneId.of("UTC"))).plusDays(1).toInstant(ZoneOffset.UTC)));
final String name = (String) recordAttr.get(ATTR_NAME);
final VEvent icalEvent = new VEvent(startDate, endDate, name);
String recordAttrUid = (String) recordAttr.get(ATTR_UID);
if (!recordAttrUid.isEmpty())
{
this.uid = new Uid(recordAttrUid.split("UID:")[1].replaceAll("([\n\r])", ""));
}
else
{
final UidGenerator uidGenerator = new UidGenerator(ATTR_UID_GEN);
this.uid = uidGenerator.generateUid();
}
icalEvent.getProperties().add(this.uid);
icalEvent.getProperties().add(new Priority(5));
Long sequence = (Long) recordAttr.get(ATTR_SEQUENCE);
this.sequence = sequence != null ? sequence + 1 : 0;
icalEvent.getProperties().add(new Sequence(Math.toIntExact(this.sequence)));
icalEvent.getProperties().add(new Created());
icalEvent.getProperties().add(new LastModified());
icalEvent.getProperties().add(new Location());
final Description description = new Description((String) recordAttr.get(ATTR_DESCRIPTION));
icalEvent.getProperties().add(description);
final Organizer organizer = new Organizer("[email protected]");
organizer.getParameters().add(new SentBy("[email protected]"));
icalEvent.getProperties().add(organizer);
final VAlarm vAlarm = new VAlarm(new Dur(0, -1, 0, 0));
vAlarm.getProperties().add(Action.DISPLAY);
vAlarm.getProperties().add(new Description((String) recordAttr.get(ATTR_DESCRIPTION)));
icalEvent.getAlarms().add(vAlarm);
calendar.getComponents().add(icalEvent);
this.icsFile = new File(name + ".ics");
final FileOutputStream fout = new FileOutputStream(this.icsFile);
final CalendarOutputter outputter = new CalendarOutputter();
outputter.output(calendar, fout);
This code produces the following ics-String:
BEGIN:VCALENDAR
PRODID:-//my ProdId
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
BEGIN:VEVENT
DTSTAMP:20201210T091704Z
DTSTART;VALUE=DATE:20201210
DTEND;VALUE=DATE:20201211
SUMMARY:e
UID:20201210T091704Z-uidGen@fe80:0:0:0:dd32:894f:88da:fde6%wlan0
PRIORITY:5
SEQUENCE:0
CREATED:20201210T091705Z
LAST-MODIFIED:20201210T091705Z
LOCATION:
DESCRIPTION:
ORGANIZER;[email protected]:[email protected]
BEGIN:VALARM
TRIGGER:-PT1H
ACTION:DISPLAY
DESCRIPTION:
END:VALARM
END:VEVENT
END:VCALENDAR