John Paolo Pancho
John Paolo Pancho

Reputation: 1

Use of multiple cc and/or bcc in google apps script MailApp.sendEmail

When I run the program, only [email protected] gets bcc'ed.

I've debugged the program and each variable is logged correctly.

MailApp.sendEmail(
    EPEmail, 
    "Internship Opportunity at "+OP,
    emailText,{
        cc:Manager1,
        cc:EPManager2,
        cc:EPManager3,
        bcc:Boss,
        bcc:"[email protected]"}
);

Upvotes: 0

Views: 6555

Answers (2)

t33n
t33n

Reputation: 343

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: '[email protected],[email protected]'
});

    

}

Upvotes: 0

ross
ross

Reputation: 2774

Requirement:

Send emails with multiple cc / bcc addresses.


Solution:

From the "Advanced parameters" section of sendEmail documentation:

a comma-separated list of email addresses to CC

This means we can concatenate the variables and separate them with commas using the + operator to achieve your goal.


Example:

MailApp.sendEmail(
    EPEmail, 
    "Internship Opportunity at "+OP,
    emailText,{
        cc:Manager1+','+EPManager2+','+EPManager3,
        bcc:Boss+','+"[email protected]"}
);

Reference:

Upvotes: 3

Related Questions