首先,我将设置方案。我正在使用双周库来创建VEvent和ICalendar。一切都很好(下面的代码)。我可以成功向Google发送日历邀请以及相应的“接受,拒绝,添加到日历”'选项可用。
当我向Outlook发送相同的邮件时,我没有收到正确的邀请。邮件的格式是希望收件人发送邀请 - 不被邀请,也不会添加到他/她的日历中。
框架:
爪哇 - JavaMailSender - 春季靴子 - 双周刊
代码正常运作。问题在于Outlook处理日历邀请的区别。
这是Java代码......
@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();
VEvent event = new VEvent();
Attendee attendee = new Attendee("Juniper", "blank@blank.com");
attendee.setRsvp(true);
attendee.setRole(Role.ATTENDEE);
attendee.setParticipationStatus(ParticipationStatus.NEEDS_ACTION);
attendee.setParticipationLevel(ParticipationLevel.REQUIRED);
event.addAttendee(attendee);
event.setSummary("hello");
DateTime dt = new DateTime(2016, 12, 28, 12, 0);
DateTime et = new DateTime(2016, 12, 28, 13, 30);
Date starts = (Date) dt.toDate();
Date ends = (Date) et.toDate();
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("555xxx");
event.setOrganizer("blank@blank.com");
event.setLocation("Small");
ical.addEvent(event);
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("blank@blank.com");
message.addRecipient(Message.RecipientType.TO, new InternetAddress("blank@blank.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);
}
}
这是ICS ......
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Michael Angstadt//biweekly 0.6.0//EN BEGIN:VEVENT
DTSTAMP:20161223T203840Z ATTENDEE;RSVP=TRUE;ROLE=REQ-
PARTICIPANT;PARTSTAT=NEEDS-ACTION;CN=Juniper:mail
to:blank@blank.com
SUMMARY:hello
DTSTART:20161228T170000Z
DTEND:20161228T183000Z
DURATION:PT1H
UID:555****
ORGANIZER:mailto:blank@blank.com
LOCATION:Small
BEGIN:VALARM
ACTION:DISPLAY
TRIGGER;RELATED=START:PT15M
END:VALARM
END:VEVENT
END:VCALENDAR
以下是已打开的Outlook电子邮件(请注意它是如何撰写的邮件)...
以下是已打开的Gmail电子邮件...
我发现文档有限,并希望有人可能/遇到/遇到同样的问题。谢谢你的阅读。
答案 0 :(得分:1)
我取消了两周一次的图书馆......虽然我觉得解决方案很简单,我可能会重新审视这个问题。为了记录,biweekly是一个很好的库,可以帮助在Java中创建VEVENTS和VCALENDARS。
我退回去手动制作ics。此格式功能齐全,适用于Gmail和Outlook。
StringBuffer sb = new StringBuffer();
StringBuffer buffer = sb.append(
"BEGIN:VCALENDAR\n"
+ "PRODID:-//Microsoft Corporation//Outlook 9.0 MIMEDIR//EN\n"
+ "VERSION:2.0\n"
+ "METHOD:REQUEST\n"
+ "BEGIN:VTIMEZONE\n"
+ "TZID:America/New_York\n"
+ "X-LIC-LOCATION:America/New_York\n"
+ "BEGIN:STANDARD\n"
+ "DTSTART:20071104T020000\n"
+ "TZOFFSETFROM:-0400\n"
+ "TZOFFSETTO:-0500\n"
+ "TZNAME:EST\n"
+ "END:STANDARD\n"
+ "BEGIN:DAYLIGHT\n"
+ "DTSTART:20070311T020000\n"
+ "TZOFFSETFROM:-0500\n"
+ "TZOFFSETTO:-0400\n"
+ "TZNAME:EDT\n"
+ "END:DAYLIGHT\n"
+ "END:VTIMEZONE\n"
+ "BEGIN:VEVENT\n"
+ "ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:" + email + "\n"
+ "ORGANIZER:MAILTO:hockeyonicethricewastoldcold?.com\n"
+ "DTSTART;TZID=America/New_York:" + invite.getDateStart() + "\n"
+ "DTEND;TZID=America/New_York:" + invite.getDateEnd() + "\n"
+ "LOCATION:Conference room\n"
+ "TRANSP:OPAQUE\n"
+ "SEQUENCE:0\n"
+ "UID:" + invite.getUID() + "\n"
+ "DTSTAMP:20051206T120102Z\n"
+ "CATEGORIES:Meeting\n"
+ "DESCRIPTION:" + invite.getDescription() + "\n"
+ "SUMMARY:" + invite.getDescription() + "\n"
+ "PRIORITY:5\n"
+ "CLASS:PUBLIC\n"
+ "BEGIN:VALARM\n"
+ "TRIGGER:PT1440M\n"
+ "ACTION:DISPLAY\n"
+ "DESCRIPTION:Reminder\n"
+ "END:VALARM\n"
+ "END:VEVENT\n"
+ "END:VCALENDAR");
MimeMessage message = javaMailSender.createMimeMessage();
message.addHeaderLine("charset=UTF-8");
message.addHeaderLine("component=VEVENT");
message.addHeaderLine("method=REQUEST");
message.setFrom(invite.getUserID());
message.addRecipient(Message.RecipientType.TO, new InternetAddress(email));
message.setSubject(invite.getSubject());
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setHeader("Content-Class", "urn:content-classes:calendarmessage");
messageBodyPart.setHeader("Content-ID", "calendar_message");
messageBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(buffer.toString(), "text/calendar")));
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
javaMailSender.send(message);
}
答案 1 :(得分:0)
我遇到了同样的问题。添加ical.setMethod("REQUEST");
为我解决了这个问题。