【问题标题】:Google Script - Send Email using aliasGoogle Script - 使用别名发送电子邮件
【发布时间】:2020-12-02 23:27:37
【问题描述】:

我有以下代码

  var mailOptions = {};
  mailOptions.attachments = attachmentArray;
  mailOptions.htmlBody = htmlbody;
  var alias = ??? // I have no idea what to put here. I've tried just putting in a string with the address
  mailOptions.from = alias;

  if(email){
  GmailApp.sendEmail(email, subject,"",mailOptions); 

我正在尝试使用别名发送电子邮件,但我有多个别名可供选择。我在某个地方看到了我可以使用它的地方

Gmail.Users.Settings.SendAs.Get

我应该提到,在我编写脚本时,我不是电子表格的所有者。原所有者拥有 G Suite 帐号,并希望使用上面的别名。所以这不是我的别名,但他们将是运行脚本的人。

【问题讨论】:

  • 文档说它是一个字符串,它必须是您已经创建的别名之一。如果您已经创建了一个,您就会知道该放什么。
  • 文档比 Cooper 写的更具体:“应该发送电子邮件的地址,必须是 getAliases() 返回的值之一”
  • 那么我想做的事可能吗?我已经阅读了文档,但我不知道这是否可能/如何做到。

标签: google-apps-script gmail


【解决方案1】:

首先,您应该为 Gmail 添加一个别名。您可以从 Gmail 网络应用程序执行此操作(请参阅Send emails from a different address or alias)您也可以使用 Gmail API 执行此操作(请参阅Managing Aliases

一旦您的 Gmail 帐户有一个或多个别名,您就可以通过将别名的电子邮件地址添加到 GmailApp.sendEmail 选项参数的相应属性来使用从别名发送电子邮件。

相关

【讨论】:

    猜你喜欢
    • 2020-10-20
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 2016-11-22
    • 2018-10-13
    • 1970-01-01
    • 2014-01-12
    相关资源
    最近更新 更多