英文:
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")来实现,但我不知道如何在这里添加它
提前感谢!
英文:
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
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);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论