Sending calendar invites to non-Google accounts vi

2019-05-22 20:31发布

I've created a Google Form that enters information into a Google Sheet on submitting.

I've created a piece of Google Apps Script code that runs on submit, that creates a Calendar Event and uses the Advanced Calendar API to create the event on a non-primary Google Calendar that I've created in the Form owner's Google account.

As part of the event object, I'm setting an attendees property array of recipient email addresses that are to receive invitations to the event. I'm also setting sendNotifications to true.

When the event is created via the API, I can see that the event is created in the calendar I've specified. The attendees list is populated with the recipient email addresses I've specified.

Recipients that have Google accounts will have the calendar event added as a tentative appointment directly into their calendar. Non-Google recipients (e.g. Hotmail users, Exchange users, Office 365 etc.) simply do not receive the invitation.

Further to this, editing the created event through the calendar UI prompts me to "update guests" of changes. Confirming this causes the non-Google recipient to successfully receive the email notification of the event change. Additionally, creating an event through the calendar UI directly and specifying the non-Google attendees also causes the invite to be delivered successfully.

It's just that creating the event through the Calendar API doesn't seem to work.

To complicate matters further, if I visit the Google events reference page, and use the Try it! Form (connecting to the API using OAuth ) then I can post data to the API and successfully receive an event invitation from a non-Google address.

I suppose I could wire up some sort of Google API Service Account, write some Google Apps Script code to authorize with that service account via an OAuth plug-in, and attempt to call the API via some sort of external API request to the Google Calendar API - but I'm unsure if this will work and I'd have to figure out how to get the OAuth stuff working from within Google Apps Script. Even so, it seems a little excessive when the Google Apps Script supports using the Calendar API internally anyhow.

Just to add: I've authorised the script to use the Calendar API via the Advanced Google services area of the Script Editor as well as the Developers Console, as recommended in this article.

I've also found this article which suggests patching an event to support sending invites - the result is the same and still doesn't work to non-Google accounts.

My code is as follows:

  // set variables
  var appointmentWith = "Nick W";
  var location = "The Boardroom";
  var description = "Add some notes to the appointment";
  var calendar = "1v1.....u80@group.calendar.google.com"; // calendar id of calendar
  /*
  joinedStart and endDate are set elsewhere
  */

  // create an event object
  var event = {
    summary: appointmentWith, // the title of the appointment
    location: location, // the location of the appointment
    description: description, // the form description / submitted values
    start: {
      dateTime: joinedStart.toISOString() // start time of the appointment
    },
    end: {
      dateTime: endDate.toISOString() // end time of the appointment
    },
    sendNotifications: true, // email the invite
    attendees: [
      {email: recipient}, // set the recipient email address
      {email: "user@googleaccount.com"},
      {email: "non-google-user@hotmail.com"}
    ]
  };



  Logger.log("creating new calendar event");
  event = Calendar.Events.insert(event, calendar); // creates the event but won't notify non-Google email accounts
  Logger.log(event.id);
  Logger.log("new calendar event created");

  // attempting to patch the event in the hope this will fix the issue
  Logger.log("sending further invites");
  event.attendees.push({email:"user@hotmail.com"});
  event = Calendar.Events.patch(event, calendar, event.id, { sendNotifications:true});

  Logger.log("sent");

1条回答
对你真心纯属浪费
2楼-- · 2019-05-22 21:18

This:

sendNotifications: true, // email the invite

should be set as a request parameter, not as a part of the Event body.

Calendar.Events.insert(event, calendar, {sendNotifications:true})

查看更多
登录 后发表回答