0
votes

I've made a script to send an email using data I take from a Sheet.

function sendEmails() {
  var foglio = SpreadsheetApp.getActiveSheet();
var emailRange = SpreadsheetApp.getActiveSpreadsheet().getRange("G21");
  var nomeRange = SpreadsheetApp.getActiveSpreadsheet().getRange("B21");
  var cognomeRange = SpreadsheetApp.getActiveSpreadsheet().getRange("C21");
  var nomeaddettoRange = SpreadsheetApp.getActiveSpreadsheet().getRange("D21");
  var numeroRange = SpreadsheetApp.getActiveSpreadsheet().getRange("E21");
  var emailaddettoRange = SpreadsheetApp.getActiveSpreadsheet().getRange("H21");
  var noteRange = SpreadsheetApp.getActiveSpreadsheet().getRange("F21");
 
  var emailAddress = emailaddettoRange.getValues();
  var nome = nomeRange.getValues();
  var cognome = cognomeRange.getValues();
  var nomeaddetto = nomeaddettoRange.getValues();
  var numero = numeroRange.getValues();
  var email = emailRange.getValues();
  var note=noteRange.getValues();

      var subject = 'Un cliente ti ha cercato oggi!';
      var message = 'Ciao ' + nomeaddetto + ', \n\n' + 'oggi ha chiamato il/la sig./ra ' + nome + ' '+ cognome+ ' il suo numero di ricontatto è '+
      numero + ' e la sua mail è ' + email +'.'+' Ha detto che ' + note;

  MailApp.sendEmail(emailAddress, subject, message);
      
SpreadsheetApp.flush();
    }

It Works, except for Email Address, if i put a string and i write an email, it works, once i use emailAddress it says parameters (number[],String,String) does not correspond to the signature of the method for MailApp.sendEmail.

1

1 Answers

0
votes

Answer:

You need to use getValue() not getValues().

More Information:

As per the documentation, getValue() returns the value of an individual cell, whereas getValues() returns an array of values of the specified range.

As your range is a single cell, and you are using getValues(), emailAddress is being set to the array ["[email protected]"] instead of the string "[email protected]".

Code Change:

You need to change this line:

var emailAddress = emailaddettoRange.getValues();

to:

var emailAddress = emailaddettoRange.getValue();

References: