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

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

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

问题

这是我的代码:

  1. function addToEvent() {
  2. var guest = "";
  3. var calendar = '';
  4. var event = "";
  5. var cal = CalendarApp.getCalendarById(calendar);
  6. var theEvent = cal.getEventSeriesById(event);
  7. theEvent.addGuest(guest);
  8. }

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

提前感谢!

英文:

Thats my code:

  1. function addToEvent() {
  2. var guest = "";
  3. var calendar = '';
  4. var event = "";
  5. var cal = CalendarApp.getCalendarById(calendar);
  6. var theEvent = cal.getEventSeriesById(event);
  7. 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版本。

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

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.

  1. function addGuestAndSendNotification(calendarId, eventId, newGuestEmailAddress) {
  2. eventId = eventId.substring(0, eventId.indexOf('@google.com'));
  3. var event = Calendar.Events.get(calendarId, eventId);
  4. var attendees = event.attendees;
  5. if (!attendees) attendees = [];
  6. attendees.push({ email: newGuestEmailAddress });
  7. var resource = { attendees: attendees };
  8. var args = { sendUpdates: "all" };
  9. Calendar.Events.patch(resource, calendarId, eventId, args);
  10. }

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:

确定