Google脚本:将访客添加到事件(Google日历),但不发送邀请邮件。

huangapple go评论69阅读模式
英文:

Google Script: Add guest to event (Google Calender) but it doesn't send a invitation email

问题

这是我的代码:

function addToEvent() {
  var guest = "";
  var calendar = '';
  var event = "";

  var cal = CalendarApp.getCalendarById(calendar);
  var theEvent = cal.getEventSeriesById(event);

  theEvent.addGuest(guest);
}

一切都正常工作,但它不会向嘉宾发送邀请邮件。
我知道可以使用(sendUpdates: "all")来实现,但我不知道如何在这里添加它 Google脚本:将访客添加到事件(Google日历),但不发送邀请邮件。

提前感谢!

英文:

Thats my code:

function addToEvent() {

 var guest = "";
 var calendar = '';
 var event = "";

 var cal = CalendarApp.getCalendarById(calendar);
 var theEvent = cal.getEventSeriesById(event); 

 theEvent.addGuest(guest); }

Everything works but it does not send an invitation mail to the guest.
I know it works with ( sendUpdates: "all" ) but I dont know how to add that here Google脚本:将访客添加到事件(Google日历),但不发送邀请邮件。

Thanks in Advance!

答案1

得分: 0

尝试下面的代码。我已经测试过,它对我有效。只需确保你已经在高级服务中启用了Calendar API的V3版本。

function addGuestAndSendNotification(calendarId, eventId, newGuestEmailAddress) {
    
  eventId = eventId.substring(0, eventId.indexOf('google.com'));
    
  var event = Calendar.Events.get(calendarId, eventId);
  var attendees = event.attendees;
  if (!attendees) attendees = [];
  attendees.push({ email: newGuestEmailAddress });
    
  var resource = { attendees: attendees };
  var args = { sendUpdates: "all" };
    
  Calendar.Events.patch(resource, calendarId, eventId, args);
}
英文:

Try the below code. I have tested it and it works for me.
Just make sure you have enabled the V3 of Calendar API in advanced services.

function addGuestAndSendNotification(calendarId, eventId, newGuestEmailAddress) {

  eventId = eventId.substring(0, eventId.indexOf('@google.com'));

  var event = Calendar.Events.get(calendarId, eventId);
  var attendees = event.attendees;
  if (!attendees) attendees = [];
  attendees.push({ email: newGuestEmailAddress });

  var resource = { attendees: attendees };
  var args = { sendUpdates: "all" };

  Calendar.Events.patch(resource, calendarId, eventId, args);
}

huangapple
  • 本文由 发表于 2023年3月8日 18:15:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75671741.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定