以前可以使用的Calendar Invite已停止为Outlook电子邮件客户端工作,但已为Gmail客户端工作

时间:2018-08-20 06:40:33

标签: java outlook sendgrid ical4j outlook-calendar

我正在使用Sendgrid发送电子邮件,并使用Ical4j库创建日历邀请。下面提到的代码在几个月前运行良好,并且通过发送的所有日历邀请还显示了所有必需的内容,例如;通过任何电子邮件客户端(主要是Outlook和Gmail)接收到的“接受/拒绝”按钮,开始日期和结束日期等。但是现在,我可以通过此代码发送日历邀请,但是一旦通过Outlook电子邮件客户端收到了日历邀请(在Gmail上运行正常);它显示为(.ics)附件,而不是所有必需的日历邀请控件。

我确实尝试了几种方法,但是都没有奏效。

参考链接

下面是使用sendgrid api发送日历邀请的Java代码

public Response sendCalendarInvite(Show show, List<String> tos, String cc, String subject, String body,
      Calendar calendarEvent) {
    Response response = new Response();
    log.debug(
        "Sending Calendar Invite tos : {}, CC: {}, Subject : {}, Body : {}, calendarEvent : {}",
        tos, cc, subject, body, calendarEvent);
    if (!ApplicationConfig.isEmailEnabled()) {
      log.warn("Email not enabled. Check property [email.enabled] in application.properties");
      return response;
    }
    try {
      CalendarOutputter calendarOutputter = new CalendarOutputter();
      Writer wtr = new StringWriter();
      calendarOutputter.setValidating(true);
      calendarOutputter.output(calendarEvent, wtr);
      StringBuffer buffer = ((StringWriter) wtr).getBuffer();

      Mail mail = new Mail();
      mail.setFrom(
          new Email("testfrom@test.com", "test name"));
      mail.setSubject(subject);

      Content content = new Content("text/calendar", String.valueOf(buffer).intern());
      mail.addContent(content);

      Personalization personalization = new Personalization();
      personalization.addHeader("charset", "utf-8");
      personalization.addHeader("method", calendarEvent.getMethod().getValue());
      for (String to : tos) {
        personalization.addTo(new Email(to));
      }
      mail.addPersonalization(personalization);

      Request request = new Request();
      request.setMethod(Method.POST);
      request.setEndpoint(END_POINT);
      request.setBody(mail.build());

      response = sg.api(request);
      log.debug("{}, {}, {}", response.getStatusCode(), response.getBody(), response.getHeaders());
    } catch (IOException ex) {
      log.error("Calendar invite Exception", ex);
      response.setBody(ex.getMessage());
      throw new CustomException(CustomError.INTERNAL_SERVER_ERROR,
          "Error occurred while sending Calendar invite");
    } finally {
      return response;
    }
  }
}

我要发送的日历邀请

BEGIN:VCALENDAR
PRODID:-//XYZ//iCal4j 2.1//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VTIMEZONE
TZID:Etc/GMT
TZURL:http://tzurl.org/zoneinfo/Etc/GMT
X-LIC-LOCATION:Etc/GMT
BEGIN:STANDARD
TZOFFSETFROM:+0000
TZOFFSETTO:+0000
TZNAME:GMT
DTSTART:16010101T000000
RDATE:16010101T000000
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTAMP:20180820T091756Z
TZID:Etc/GMT
STATUS:CONFIRMED
ORGANIZER;CN=XXXX:mailto:donotreply@xxxx.com
UID:00803a42-e17d-41a9-b552-036f14c7799e
DTSTART:20180820T153000Z
DTEND:20180820T163000Z
LOCATION:Test Subject
SUMMARY:Test Summary
DESCRIPTION:Test Desc
LAST-MODIFIED:20180820T091756Z
SEQUENCE:0
TRANSP:OPAQUE
CLASS:PUBLIC
PRIORITY:5
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=
 TRUE;X-NUM-GUESTS=0;CN=XYZ:mailto:xxxx.xxxx@yyyy.com
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=
 TRUE;X-NUM-GUESTS=0;CN=XYZ:mailto:xxxxxxxx@gmail.com
END:VEVENT
END:VCALENDAR

2 个答案:

答案 0 :(得分:0)

我没有任何解释说明为什么这些东西以前对您有用,但是您使用的电子邮件MIME结构确实很初级。有关适用于大多数客户端的MIME结构,请参见Multipart email with text and calendar: Outlook doesn't recognize ics

答案 1 :(得分:0)

SendGrid似乎不再允许包含以下行的.ics附件文件:

CALSCALE:GREGORIAN