I wrote the script below to send a template html email to a list of emails in a sheet through an alias (the alias is already in my gmail account and I have provided access).
function sendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet1=ss.getSheetByName('list');
var n=sheet1.getLastRow();
for (var i = 2; i < n+1 ; i++ ) {
var emailAddress = sheet1.getRange(i,1).getValue();
var html = HtmlService.createTemplateFromFile('template').evaluate().getContent();
var aliases = GmailApp.getAliases();
Logger.log(aliases);
GmailApp.sendEmail({
to: emailAddress,
from: "[email protected]",
subject: ('Document'),
htmlBody: html,
});
}
}
But I am getting the error:
Exception: The parameters (String) don't match the method signature for GmailApp.sendEmail. sendEmail @ Code.gs:13
Helppp, please!
I've checked your script and found that the main issue is with the parameter structure used in your GmailApp.sendEmail()
line. According to this official sample for sending email via alias on the GmailApp class article, the parameter structure should be something like this:
GmailApp.sendEmail(me, 'From an alias', 'A message from an alias!', {'from': aliases[0]});
SOLUTION
You can test this tweaked script:
UPDATED
function sendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet1=ss.getSheetByName('list');
var n=sheet1.getLastRow();
for (var i = 2; i < n+1 ; i++ ) {
var emailAddress = sheet1.getRange(i,1).getValue();
var html = HtmlService.createTemplateFromFile('template').evaluate().getContent();
var aliases = GmailApp.getAliases();
Logger.log(aliases);
GmailApp.sendEmail(emailAddress, 'Document', 'Please see the message.', {
htmlBody: html,
name: "Sender Name", //On my testing, it looks "name" (Sender Name) is needed for the alias email to work and for the email to be sent to to recipient successfully
from: aliases[0]
});
}
}