【问题标题】:Google Apps Script: Unable to send emails using createEvent()Google Apps 脚本:无法使用 createEvent() 发送电子邮件
【发布时间】:2019-11-01 14:06:40
【问题描述】:

我有以下代码,但与会者无法接收有关该活动的电子邮件。虽然事件反映在他们的日历中。

    var options = {  
     description: description,
     location: location,
     guests: email_address,
     sendInvites: true
   }
   var event = CalendarApp.getCalendarById(calendarId).createEvent(title,
                start_datetime, end_datetime,
                options);

我也将 oauthScopes 添加到了 appsscript.json 中。

 "oauthScopes": [
   "https://www.googleapis.com/auth/calendar",
   "https://www.google.com/calendar/feeds"
 ]

这似乎是一个授权问题,但不知道如何解决。

【问题讨论】:

  • 欢迎来到 stackOverflow。在选项中,“Guests”有一个名为“email_address”的变量的值。能否请您附上创建此变量的代码?

标签: email google-apps-script google-calendar-api


【解决方案1】:

从浏览器编辑器运行脚本时,您无需手动添加任何范围。

您的代码非常适合我 :) 我添加了一些变量来完成它,但效果很好 -

function myFunction() {
  var calendarId = 'self@gmail.com'; // if using your own or default calendar ID
  var description = 'test desc';

  // ref link - https://developers.google.com/apps-script/reference/calendar/calendar-app#advanced-parameters_4  
  var email_address = 'contact1@gmail.com, contact2@gmail.com';
  // comma separated guest list 

  var title = 'test title';
  var start_datetime = new Date();
  var end_datetime = new Date();
  var options = {  
    description: description,
    guests: email_address,
    sendInvites: true
  }
  var event = CalendarApp
  .getCalendarById(calendarId)
  .createEvent(title, start_datetime, end_datetime, options);
}

我的默认清单文件如下所示 -

{
  "timeZone": "Asia/Kolkata",
  "dependencies": {
  },
  "exceptionLogging": "STACKDRIVER"
}

似乎没有添加其他范围。但是,当我查看我的 文件 > 项目属性 > 范围时,脚本似乎只添加了一个范围 -

OAuth Scope required by script:

https://www.googleapis.com/auth/calendar

希望这会有所帮助。

编辑说明:忘记添加 -

也收到了电子邮件通知

【讨论】:

  • 感谢您确认 Sourabh。我遇到了问题,我正在为过去的日期创建活动,因为不会发送电子邮件邀请。 :)
  • 啊!我懂了。抱歉,我没有将其视为一个场景,但这是有道理的。感谢告知。
猜你喜欢
  • 1970-01-01
  • 2021-11-21
  • 2013-08-15
  • 1970-01-01
  • 2020-12-15
  • 2016-05-05
  • 2020-05-10
  • 1970-01-01
相关资源
最近更新 更多