【问题标题】:Google Scripts: Error when sendEmail to bcc listGoogle Scripts:将电子邮件发送到密件抄送列表时出错
【发布时间】:2013-05-31 22:00:18
【问题描述】:

我正在尝试编写一个脚本来将电子邮件发送到 Google 电子表格中的分发列表。在将其移动到实时环境之前,我正在使用列表中只有 3 个电子邮件地址的测试表。我想把它发给我,然后密送名单上的每个人。如果我将电子邮件地址列表放在 sendEmail 的收件人位置,该脚本可以正常工作,但当我尝试使用 sendEmail 的密件抄送高级参数将电子邮件地址移动到密件抄送地点时,脚本就不行了。在这种情况下,我会收到以下错误:

遇到错误:无效电子邮件:[L;@130cab11

在此错误中,每次我运行脚本时,“130cab11”部分都会更改。脚本中唯一一致的部分是“遇到错误:无效电子邮件:[L; ...”

我的脚本的相关部分如下:

// Retrieve data for the Email that will be sent///
   var email_column = ss.getSheetByName(sendtosheet)
   var lastrow = email_column.getLastRow()
   var get_email_data = email_column.getRange(2,2,lastrow-1,1).getValues()
   var emailTemplate = ss.getSheetByName("Email Templates").getRange("B1").getValue()
   var aliases = GmailApp.getAliases();
      Logger.log(aliases)

//Format the email
   var advancedArgs = {bcc:get_email_data,from: aliases[0]}
   var Self = "MyEmail@mycompany.com"
   var subject = "INVITE: Upcoming Focus Group Session";
   var message = emailTemplate

//Send the email
   GmailApp.sendEmail(Self, subject, message, advancedArgs)

如果我在不使用 bcc 参数的情况下发送电子邮件并且 sendEmail 代码的结构如下:

//Send the email
   GmailApp.sendEmail(get_email_data, subject, message, {from: aliases[0]})

我已经搜索了 stackoverflow 和 google 脚本手册以及我能想到的所有其他地方,因此我们将不胜感激。

【问题讨论】:

    标签: javascript email google-apps-script


    【解决方案1】:

    您需要以字符串形式提供密件抄送列表。

    var get_email_data = email_column.getRange(2,2,lastrow-1,1).getValues()
    

    在上述语句之后,get_email_data 包含一个二维对象数组,其内容为指定范围。这就是为什么该错误消息抱怨[L;... - 它在需要一个字符串时有一个数组,但盲目地将其视为一个字符串并发现它很困难。

    在您执行此操作之前:

     var advancedArgs = {bcc:get_email_data,from: aliases[0]}
    

    ...您需要将数组的内容加入到包含逗号分隔的子字符串列表的字符串中。幸运的是,Array 方法 .toString() 可以做到这一点,即使对于这个二维数组也是如此。

    var get_email_data = email_column.getRange(2,2,lastrow-1,1).getValues()
                                     .toString();
    

    【讨论】:

      猜你喜欢
      • 2012-03-20
      • 2020-10-10
      • 1970-01-01
      • 2013-06-08
      • 1970-01-01
      • 1970-01-01
      • 2016-01-12
      • 1970-01-01
      相关资源
      最近更新 更多