0
votes
function sendEmail(){
  var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet 1").getRange("A1");
  var emailAddress = emailRange.getValues();
  var message = 'Test message';
  var subject = 'Test subject';
  MailApp.sendEmail(emailAddress, subject, message);
}

When I try to run it, I get "Exception: The parameters (number[],String,String) don't match the method signature for MailApp.sendEmail. (line 6, file "Send_Email")"

When I copy and paste the email address from Sheet 1, A1 into the spot occupied by the variable "emailAddress", the script works.

1
Take a look at the method signature of the method and the error message again, and you will see where things went wrongOleg Valter

1 Answers

2
votes

Explanation:

Assuming that your sheet name is "Sheet 1" and not "Sheet1", the mistake you made is located here:

emailRange.getValues();

You should use instead:

emailRange.getValue();

Solution:

function sendEmail(){
  var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet 1").getRange("A1");
  var emailAddress = emailRange.getValue();
  var message = 'Test message';
  var subject = 'Test subject';
  MailApp.sendEmail(emailAddress, subject, message);
}

Related:

What does the range method getValues() return and setValues() accept?