Я написал фрагмент кода для автоматической отправки электронных писем из списка в листе Google (который работает), но когда я хочу добавить письмо с псевдонимом, я не могу заставить его работать. Любая помощь будет принята с благодарностью. Вот код:
// This constant is written in column C for rows for which an email
// has been sent successfully.
var EMAIL_SENT = 'EMAIL_SENT';
/**
* Sends non-duplicate emails with data from the current spreadsheet.
*/
function sendEmails2() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows =3; // Number of rows to process
// Fetch the range of cells A2:E3
var dataRange = sheet.getRange(startRow, 1, numRows, 5);
// add the attachments variables
var contents = DriveApp.getFolderById("").getFiles();
var attachments = [];
while (contents.hasNext()) {
var file = contents.next();
{
attachments.push(file);
}
}
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[0]; // First column
var message = row[1]; // Second column
var cuota = row[3]; // Fourth column
var emailSent = row[4]; // Fifth column
if (emailSent !== EMAIL_SENT && emailAddress !== "#N/A" && cuota !== 0) {
// Prevents sending duplicates, no emails and parents that have already paid
var subject = 'Recordatorio de cuota';
//Do not forget to remove EMAIL_SENT once done otherwise it won't work a 2nd time
var me = Session.getActiveUser().getEmail();
var aliases = GmailApp.getAliases()
GmailApp.sendEmail(emailAddress,subject, message, {attachments: attachments},
{from: aliases[0]};
sheet.getRange(startRow + i, 5).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}