Javamail每两周一次的Gmail日历邀请作为ICS文件出现



我正在尝试向Gmail地址发送日历邀请。我正在使用Spring,双周刊和javamail库。邀请已发送,但在 gmail 中它不会作为日历进入,但我收到一封主题为"您被邀请参加会议"的电子邮件。它有一个附件ICS,其中包含我编码的邀请的详细信息。

请帮助了解我如何在谷歌中获得实际邀请,而不是附有 ICS 文件的电子邮件。如果我发送到 Outlook,邀请工作正常。

@Service
public class CalendarEvent {
private JavaMailSender javaMailSender;
@Autowired
public CalendarEvent(JavaMailSender javaMailSender) {
this.javaMailSender = javaMailSender;
}
public void createCal() throws MessagingException, ParseException, IOException {
ICalendar ical = new ICalendar();
EmailInvite invite =new EmailInvite();
VEvent event = new VEvent();
Attendee attendee = new Attendee("xx", "xx.xx@gmail.com");
attendee.setRsvp(true);
attendee.setRole(Role.ATTENDEE);
attendee.setParticipationStatus(ParticipationStatus.NEEDS_ACTION);
attendee.setParticipationLevel(ParticipationLevel.REQUIRED);
event.addAttendee(attendee);
event.setSummary(invite.getSubject());
SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd HH:MM:SS"); 
Date starts = new Date();
Date ends  = new Date();
try {
starts=ft.parse(invite.getDateStart());
ends=ft.parse(invite.getDateEnd());
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

DateStart thisStart = new DateStart(starts, true);
DateEnd dateEnd = new DateEnd(ends, true);
event.setDateStart(thisStart);
event.setDateEnd(dateEnd);
Duration reminder = new Duration.Builder().minutes(15).build();
Trigger trigger = new Trigger(reminder, Related.START);
Action action = new Action("DISPLAY");
VAlarm valarm = new VAlarm(action, trigger);
event.addAlarm(valarm);
Duration duration = new Duration.Builder().hours(1).build();
event.setDuration(duration);
event.setUid(invite.getUID());
event.setOrganizer(invite.getUserID());
event.setLocation("Small");
ical.addEvent(event);
ical.setMethod("REQUEST");
String str = Biweekly.write(ical).go();
MimeMessage message = javaMailSender.createMimeMessage();
message.addHeaderLine("charset=UTF-8");
message.addHeaderLine("component=VEVENT");
message.addHeaderLine("method=REQUEST");
message.setFrom("abc@lxyz.com");
message.addRecipient(Message.RecipientType.TO, new InternetAddress("xx.xx@gmail.com"));
message.setSubject("You're Invited to a Meeting");
// 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(str, "text/calendar")));// very important

Multipart multipart = new MimeMultipart();

multipart.addBodyPart(messageBodyPart);

message.setContent(multipart);
javaMailSender.send(message);
}
}

以下是生成并作为附件发送到gmail的ICS文件。

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Michael Angstadt//biweekly 0.6.2//EN
METHOD:REQUEST
BEGIN:VEVENT
DTSTAMP:20180601T193055Z
ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;CN=Gaurav:mailto:xx.xx@gmail.com
SUMMARY:some summary
DTSTART:20200602T130000Z
DTEND:20200602T140000Z
DURATION:PT1H
UID:2fb68918-c50e-4da2-ae97-ddcdc2d79b06
ORGANIZER:mailto:abc@lxyz.com
LOCATION:Small
BEGIN:VALARM
ACTION:DISPLAY
TRIGGER;RELATED=START:PT15M
END:VALARM
END:VEVENT
END:VCALENDAR

ics 文件看起来不错,但如果您希望您的邀请被大多数客户端识别,您还需要遵循特定的 MIME 结构。例如,请参阅:

包含文本和日历的多部分电子邮件:Outlook 无法识别 ics

(以上问题是关于Outlook的,但指南并不具体(