4

I am trying to add a guest to a Calendar event by Google Apps Script and to send an invitation as soon as my script add a guest. But I can't find a method to send an email invitation to the guest.

var events = calendar.getEvents(start_date, end_date)
event.addGuest('guest_email@gmail.com');

Is there any way to send an invitation to the guest from Apps Script?

I rewrote with Advanced Google Services but still the guest I have added can't get invitation email.

var body = {
  'sendNotification': true,
  'attendees': attendees
};

var ret = Calendar.Events.patch(body, calendarId, eventId);
Daisuki Honey
  • 157
  • 4
  • 12
  • Very similar to https://stackoverflow.com/questions/36202125/calendar-script-adding-guests-but-not-sending-an-invite/36203156#36203156 – carbontracking Jan 10 '22 at 12:12
  • Very similar again to https://stackoverflow.com/questions/53992955/how-do-i-send-the-standard-invitation-email-when-calling-addguest-on-a-calendare/55509409 with the bonus that this one has a very clear answer ! – carbontracking Jan 10 '22 at 12:54

2 Answers2

5

You can with Calendar in Advanced Google Services, for example:

var event = Calendar.Events.get(calendarId, eventId);
Calendar.Events.patch(event, calendarId, eventId, {sendNotifications: true});

Sets the sending of notifications to true

See the documentation on Calendar in the Advanced Google Services.

Bardy
  • 2,100
  • 1
  • 13
  • 11
  • Thanks. I enable Calendar API in Apps Script editor and Developer Console and run the sample code you showed but it shows an error saying "Not Found" on the first line. Do I miss anything? – Daisuki Honey Nov 30 '16 at 09:25
  • Do you have valid calendarId and eventId? – Bardy Nov 30 '16 at 09:36
  • I got calenderId and eventId by CalendarApp.getCalendarsByName()[0].getId() and CalendarApp.getCalendarsByName()[0].getEvents().getId() but I will try to get in other way. Thanks! – Daisuki Honey Nov 30 '16 at 20:02
  • The example in the guide suggests that the default ID is as follows: `var calendarId = 'primary';` – Bardy Nov 30 '16 at 20:07
  • Hmm.. I mixed Apps Script Calendar code and Calendar API code. Maybe it caused the error. I will rewrite with Calendar API code. – Daisuki Honey Dec 01 '16 at 05:26
  • Thanks. I rewrote my program with Advanced Google Services and succeeded to add a guest but the guest still doesn't get invite email. (I showed the current code above.) – Daisuki Honey Dec 16 '16 at 03:32
  • 1
    I am wondering notification Bardy mentioned is the event notification a user can get 10 minutes in advance of the event (by default). What I need is to send an invitation to a guest when I add him to a calendar event. Sorry, if I am not clear. – Daisuki Honey Dec 16 '16 at 03:41
  • According to this developers.google.com/calendar/api/v3/reference/events/patch sendNotifications has been deprecated and now you need to use sendUpdates. However I wonder if this will send notifications to all previously invited attendees as well leading to excessive e-mails, i.e. once you are invited, you will receive an update each time someone lese is invited also ?? – carbontracking Jan 10 '22 at 12:12
0

I know this is an old topic but I had to send notification to guest and I found this post.

I succesfully send notification without API by using options in the creation of event.

var oNewEvent = oCalendar.createEvent(oEvents[i][1] + ' ouvre', dBegda,dEndda, 
{
    location: oEvents[i][5],
    guests:oEvents[i][7],
    sendInvites: true,
});

Hope it can help somebody else.

YannL.
  • 11
  • 2
  • The example above creates an event and sends and e-mail to the guests at the same time. The OP was asking how to send an e-mail invitation in the case of an event that already exists. – carbontracking Jan 10 '22 at 12:03
  • I have the event details on a sheet. As columns, i have the following: Event name, Start time, End time, Attendees. I am looping over the rows to create an event with gmeet link for each row. I want the invite to received by Attendees over email. i had no luck with setting the argument sendInvites: true. Also the attendees are many i. e. there are multiple comma separated email addresses in each cell in the column with Attendees. Any pointers how to go about? – user1327454 Jun 25 '22 at 09:28
  • By the way, I used the code here https://gist.github.com/tanaikech/94791d48823e9659aa376cf7f0161d9b#gas – user1327454 Jun 25 '22 at 09:28