java—使用publish方法通过电子邮件发送ical4j事件

xmd2e60i  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(337)

我正在尝试发送一封电子邮件,其中包含要包含在私人日历中的公开活动。我使用request方法实现了它,但这并不是我想要的行为。我不希望收件人在日历中包含活动时回答“邀请”。我发现我需要改用publish方法,但是现在我的代码不再工作了。我需要删除attendee属性,这很有意义,因为事件是公共的,每个人都可以将其包含在他们的私人日历中。但一旦我这样做了,我会收到一封没有接受/拒绝等按钮的电子邮件,但是我会收到一封包含所有信息的电子邮件,但也包括我仍然需要将电子邮件发送给收件人的通知。我正在使用net.fortuna.ical4j-library创建ical事件,下面是我的代码:

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("dontanswer@mail.com");
        organizer.getParameters().add(new SentBy("dontanswer@mail.com"));
        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);

此代码生成以下ics字符串:

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;SENT-BY=dontanswer@mail.com:dontanswer@mail.com
BEGIN:VALARM
TRIGGER:-PT1H
ACTION:DISPLAY
DESCRIPTION:
END:VALARM
END:VEVENT
END:VCALENDAR

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题