Make email interpreted as an event by email clients

I am trying to send an email that will be interpreted as an event by email clients. This is related to another issue .

This code pulls an event from a Google calendar, and then creates VEVENT from it, converts it into a frame .icsand attaches it to an email.

However, when it is received by the mail client, it treats it as an email with an attachment, but I really want it to be considered as an update of the event.

Inviation / event update

When I parse the event email, it contains two files .ics(identical contents, different file names) and a file .htmlthat contains the same DESCRIPTION:in .ics.

, , - , , , , ics html .

function fixInvitations(){
  //get the callendar named "Appraisals"
  var cApp = CalendarApp.getCalendarsByName("Bris Appraisals")[0];
  var events = cApp.getEvents(new Date(), new Date("Dec 30 2014"));

  var e = events[5];
  var icsFile = makeICS(e);
  var mail_options={
                      body:     "Your updated appraisal etc. etc.",
                      htmlBody: "<p>Your updated appraisal etc. etc.</p>",
                      name: "Appraisals Scheduling Robot",
                      noReply: true,
                      /*replyTo: ,*/
                      subject: "Your updated appraisal",
                      to: "myworkEmail@bvn.com.au, mygoogleEmail@notionparallax.co.uk",
                      attachments:[icsFile]
                    };
  Logger.log(mail_options);
  MailApp.sendEmail(mail_options);
}

function ldapDate(d){
  //TODO: make this take Bris or syd to decide on a timezone
  var formattedDate = Utilities.formatDate(d, "GMT+11:00", "yyyyMMddHHmmss");
  Logger.log([d, formattedDate])
  return formattedDate+"Z";
}

function makeICS(event){
  var e = event;
  var attendees = [];
  var guests = e.getGuestList();

  for(g in guests){
    var guest = guests[g];
    var atendee =[
    "ATTENDEE;",  "CUTYPE=INDIVIDUAL;",  "ROLE=REQ-PARTICIPANT;",
    "PARTSTAT=NEEDS-ACTION;",  "RSVP=TRUE;",  "CN="+guest.getName()+";",
    "X-NUM-GUESTS=0:mailto:"+guest.getEmail()
      ].join("");
    attendees.push(atendee);
  }

  var vcal = ["BEGIN:VCALENDAR",
              "PRODID:-//Google Inc//Google Calendar 70.9054//EN",
              "VERSION:2.0",
              "CALSCALE:GREGORIAN",
              "METHOD:REQUEST",
              "BEGIN:VEVENT",
              "DTSTART:" + ldapDate(e.getStartTime()),
              "DTEND:"+ ldapDate(e.getEndTime()),
              "DTSTAMP:" + ldapDate(new Date(Date.now())),
              "ORGANIZER;CN=" + CalendarApp.getCalendarById(e.getOriginalCalendarId()).getName() + ":mailto:" + e.getOriginalCalendarId(),
              "UID:" + e.getId(),
              attendees.join("\n"),
              "CREATED:" + ldapDate(e.getDateCreated()),
              "DESCRIPTION:" + e.getDescription(),
              "LAST-MODIFIED:" + ldapDate(new Date(Date.now())), // although if I wasn't changing things as I issue this it'd be e.getLastUpdated()
              "LOCATION:" + e.getLocation(),
              "SEQUENCE:"+Date.now(),//this is a horrible hack, but it ensures that this change will overrule all other changes.
              "STATUS:CONFIRMED",
              "SUMMARY:" + e.getTitle(),
              "TRANSP:OPAQUE",
              "END:VEVENT",
              "END:VCALENDAR"
  ].join("\n");

  var icsFile = Utilities.newBlob(vcal, 'text/calendar', 'invite.ics');
  Logger.log(vcal);
  Logger.log(icsFile);
  return icsFile;
}
+2
1

. .

, .ics, Notes, " ", . : http://camberleycricket.com/cc.nsf/calendar.ics , , .

0

Source: https://habr.com/ru/post/1530152/


All Articles