0

I am trying to write a script to send an email to a distribution list housed in a google spreadsheet. I am using a test sheet with only 3 email addresses on the list before I move this into a live environment. I'd like it to send to me, and bcc everyone on the list. The script works fine if I put the list of email addresses in the recipient spot of sendEmail, but not when I try to move the email addresses to the bcc spot using the bcc advanced argument of sendEmail. In that case I get the following error:

Error encountered: Invalid email: [L;@130cab11

In this error the "130cab11" portion changes everytime I run the script. The only consistent part of the script is "Error encountered: Invalid email: [L; ..."

The relevant portion of my script is below:

// 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 = "[email protected]"
   var subject = "INVITE: Upcoming Focus Group Session";
   var message = emailTemplate

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

This code works without error if I send the email without using the bcc argument and have the sendEmail code structured like this:

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

I have searched stackoverflow and google scripts manuals and everywhere else I can think of so any help would be appreciated.

1 Answer 1

1

You need to provide the bcc list as a string.

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

After the above statement, get_email_data contains a two-dimensional array of objects, the content of the indicated range. That's why that error message complains about [L;... - it's got an array when it wanted a string, but is blindly treating it as a string and finding it difficult.

Before you can do this:

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

... you need to join the content of your array into a string containing a comma-separated list of substrings. Luckily, the Array method .toString() will do that, even for this two-dimensional array.

var get_email_data = email_column.getRange(2,2,lastrow-1,1).getValues()
                                 .toString();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.