Error with automated email function

88 views
Skip to first unread message

Sheri Jennings

unread,
Apr 27, 2023, 3:33:26 PM4/27/23
to Google Apps Script Community
Hello! 

Total newbie here, so I appreciate your help VERY MUCH! 

I have a spreadsheet with multiple email addresses from our website sign up form. We send weekly updates to these email addresses, and I am trying to automate this process. 

I have the email addresses in a Google Sheet (Sheet 1) with a second tab (Sheet 2) containing the subject and body of the email I would like to be sent on a weekly basis to the email addresses in Sheet 1. 

I found this script online to use: 
function sendEmail() {
  
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet1=ss.getSheetByName('Sheet1');
var sheet2=ss.getSheetByName('Sheet2');
var subject = sheet2.getRange(2,1).getValue();
var n=sheet1.getLastRow();
for (var i = 2i < n+1i++){ 
var emailAddress = sheet1.getRange(i,2).getValue();
var message = sheet2.getRange(2,2).getValue();

MailApp.sendEmail(emailAddress,subjectmessage);
}


}



I am getting this error message: 
Apr 26, 2023, 12:43:08 PM
Error
Exception: The parameters ((class),String,String) don't match the method signature for MailApp.sendEmail. at sendEmail(Code:12:9)

cbmserv...@gmail.com

unread,
Apr 27, 2023, 5:08:33 PM4/27/23
to google-apps-sc...@googlegroups.com

Script looks fine. You might want to check the email addresses you have in sheet1 to ensure they are formatted correctly.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/ad00534f-556a-4d00-8375-ccb973b4af78n%40googlegroups.com.

Sheri Jennings

unread,
Apr 27, 2023, 7:08:27 PM4/27/23
to Google Apps Script Community
Thank you so very much! I verified that all email addresses are formatting correctly. Tried running it again and got the same error message :-/ Could something else be causing this to fail?

cbmserv...@gmail.com

unread,
Apr 27, 2023, 7:27:48 PM4/27/23
to google-apps-sc...@googlegroups.com

Do some debugging to see what value is in emailAddress.

 

Add this Logger.log statement as below:

 

function sendEmail() {

  

var ss = SpreadsheetApp.getActiveSpreadsheet()

var sheet1=ss.getSheetByName('Sheet1');

var sheet2=ss.getSheetByName('Sheet2');

var subject = sheet2.getRange(2,1).getValue();

var n=sheet1.getLastRow();

for (var i = 2i < n+1i++){ 

var emailAddress = sheet1.getRange(i,2).getValue();

var message = sheet2.getRange(2,2).getValue();

Logger.log(emailAddress); 

MailApp.sendEmail(emailAddress,subjectmessage);

}

 

}

It should be a nice simple email address printed. If you get something else, then its picking up some garbage from somewhere it should not.

cbmserv...@gmail.com

unread,
Apr 27, 2023, 8:13:02 PM4/27/23
to google-apps-sc...@googlegroups.com

I was looking at this email on my mobile and it was showing a line break after emailAddress in this line:

 

MailApp.sendEmail(emailAddress,subjectmessage);

 

There may be some hidden chararcters there. Delete the line and retype it.

Sheri Jennings

unread,
Apr 28, 2023, 11:44:53 AM4/28/23
to google-apps-sc...@googlegroups.com
Thanks again for helping with this. I've applied the suggestions and I'm still getting the same error. Bleh...

You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/P-ltuFXpw-Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/00dc01d97966%242f578430%248e068c90%24%40gmail.com.


--
Sheri Jennings, M.S. CCC-SLP
Speech-Language Pathologist
Owner/Director
In Reach Speech-Language Therapy LLC
Office: 503-421-8629


CBMServices Web

unread,
Apr 28, 2023, 1:26:20 PM4/28/23
to google-apps-sc...@googlegroups.com
Ok am out of ideas. But I can look at the spreadsheet and debug it for you.

Can you share the spreadsheet with me? Or if it has sensitive data, make a sample spreadsheet and send it to me?


Reply all
Reply to author
Forward
0 new messages