Make an email be interpreted as an event by mail c

2019-07-16 18:40发布

I'm trying to send an email that will be interpreted as an event by mail clients. This is related to another question of mine.

This code pulls an event from a google calendar, and then builds a VEVENT out of it, converts that to a .ics blob and attatches it to an email.

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

Inviation/event update

When I dissect an event email it contains two .ics files (identical contents, different file names) and a .html file that contains the same as the DESCRIPTION: in the .ics.

What I'd like to know is what I need to do to tell the mail client that this is an event, and if that relates to the duplicate ics files and the html file.

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;
}

1条回答
聊天终结者
2楼-- · 2019-07-16 19:31

Try sending a meeting request to a user in notes from another notes client and checking out the fields created. This is how I did this in the past.

I have some code that will create a .ics feed so the user can add them into their Notes calendar using the "add a calendar" feature if you need it. eg: http://camberleycricket.com/cc.nsf/calendar.ics Neatest way as then other calendar systems can use the feed.

查看更多
登录 后发表回答