Whenever I add a guest via the Google Calendar UI, the following dialog pops up:
If I choose "Send" it sends a nicely formatted email to the user with an option to respond to the calendar event too:
This works flawlessly when you're manually using the Google Calendar UI. Problem is I'm trying to use Google Apps Scripts to automate adding people to events.
I'm programmatically adding guests to a CalendarEvent by using addGuest():
event.addGuest("user@example.com");
However, there doesn't seem to be an option to send an email.
The closest I could find is that when you programmatically create an event, you can set sendInvites:
var event = CalendarApp.getDefaultCalendar().createEvent(
'Test',
new Date('April 5, 2029 20:00:00 UTC'),
new Date('April 5, 2029 21:00:00 UTC'),
{sendInvites: true, guests:"your.email+1@example.com"});
Logger.log(event.getId());
This sends a nicely formatted email correctly.
However, the sendInvites option only works when the event is newly created. If at a later time I call:
var event = CalendarApp.getEventById("insert_id_here");
event.addGuest("your.email+2@example.com");
... it does not send an email update (even though the event was created with sendInvites=true). This means sendInvites is transient and doesn't persist on the event.
Is there any way to sendInvites when calling addGuest() on an event? E.g. event.addGuest("user@example.com", {sendInvite: true})?
Are there any other workarounds that will produce the same email that is sent when hitting that "Send" button in the UI above?
Note: I do not want to use MailApp to send an email because it won't be nicely formatted like the one Google automatically sends out (e.g. with embedded calendar invite, attendees, description, response links, etc, etc, etc).
Update:
- I just saw getAllTagKeys in the API and was hoping I could use that to get the
sendInviteskey, but that's not the case. It is empty even for events that havesendInvitesset to true.

