在Google Apps脚本MailApp.sendEmail中使用多个抄送和/或密件抄送

时间:2019-07-04 10:13:42

标签: google-apps-script

我运行程序时,只有boss1@gmail.com被密送。

我已经调试了程序,并且正确记录了每个变量。

MailApp.sendEmail(
    EPEmail, 
    "Internship Opportunity at "+OP,
    emailText,{
        cc:Manager1,
        cc:EPManager2,
        cc:EPManager3,
        bcc:Boss,
        bcc:"boss1@gmail.com"}
);

2 个答案:

答案 0 :(得分:1)

要求:

发送具有多个抄送/密件抄送地址的电子邮件。


解决方案:

sendEmail文档的“高级参数”部分:

  

用逗号分隔的抄送电子邮件地址列表

这意味着我们可以连接变量,并使用+运算符将它们用逗号分隔,以实现您的目标。


示例:

MailApp.sendEmail(
    EPEmail, 
    "Internship Opportunity at "+OP,
    emailText,{
        cc:Manager1+','+EPManager2+','+EPManager3,
        bcc:Boss+','+"boss1@gmail.com"}
);

参考:

答案 1 :(得分:0)

function myFunction(){

  
  // html email
  var htmlEmailBody = HtmlService.createTemplateFromFile('html-template-name');

  // email title
  var subject = "sample title..";
  
  // this must be set or .sendEmail will not work. You can insert your own email address to get a copy of the email or just let it blank. Alternative you can delete bcc and just the emailAddress value to send 1 email only.
  var emailAddress = "";
  
  // same like emailAddress this must be set aswell. You can just keep it blank and use htmlBody for your html email. Alternative delete htmlBody and use normalBody for plain text email instead.
  var normalBody = "";
 

MailApp.sendEmail(emailAddress, subject, normalBody, {
  name: "Your Name",
  htmlBody: htmlEmailBody.evaluate().getContent(),
  bcc: 'sample1@gmail.com,sample2@web.de'
});

    

}