0
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.

  • Take a look at the method signature of [the method](https://developers.google.com/apps-script/reference/mail/mail-app#sendEmail(String,String,String)) and the error message again, and you will see where things went wrong – Oleg Valter is with Ukraine Sep 15 '20 at 15:45

1 Answers1

2

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?

Marios
  • 26,333
  • 8
  • 32
  • 52