Here’s my code. I adapted it with your solution, but it’s giving an error:
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 0; // First row of data to process
var numRows = sheet.getLastRow();
var lastCol = sheet.getLastColumn();
var dataRange = sheet.getRange(2, 1, numRows-startRow,lastCol).getValues(); //Get all values except the header rows
for (var i=0;i<numRows-startRow;i++){
var expire = dataRange[i][8];
if (expire < 10) {
var emailAddress = dataRange[i][7];
var subject = "Você tem um prazo de auditoria vencendo em " + dataRange[i][8] + " dias";
var emails = emailAddress.split(",");
var dataEnvio = Utilities.formatDate(dataRange[i][0], "GMT", "dd/MM/yyyy");
var dataFim = Utilities.formatDate(dataRange[i][4], "GMT", "dd/MM/yyyy");
var message = "<P><i style='color: black; font-size: 11px; font-weight:bold';> *Esta é a Proposta de encaminhamento da COAUD, de " + dataEnvio + "\n" + ", que deve ser respondida até "
+ dataFim + "<P><a style='color: black; font-size: 12px; font-weight:bold';>Identificação do Documento: </a>" + dataRange[i][2] + "<P><b style='color: black; font-size: 12px; "
+ " font-weight:bold';> Recomendação de Auditoria: </b> " + dataRange[i][3]
+"<P> ----------------------------------------------------------------------------------------------------------------------------------------------------------------"
+ "------------------------------------------------</P>"
+ "<P><i style='color: red; font-size: 10px';> NOTA: Amparada na Portaria X monitoramento. Para acessá-lo, consulte o manual de monitoramento, disponível "
+ "<A href='https://www.a.x'>aqui</A>. Contate a COA pelos telefones: XXXXXXXX/6779 e e-mail: [email protected], para maiores informações </i></P>";
// for (var email of emails) {
MailApp.sendEmail(Email.trim(), subject, "", {htmlBody: message});
// MailApp.sendEmail(Email.trim(), emailAddress, subject, "", {htmlBody: message});
}
}
}
How are these fields read and how is the email sent? Probably when there are 2 or more emails, the sending script reads everything as if it were just 1 email and does not work because it goes as invalid email.
– Sam
I take all emails from the field with this code: var emailAddress = dataRange[i][7]; And send with this: Mailapp.sendemail(emailAddress, Subject, "", {htmlBody: message});
– Roger Regor
there is no solution, so...type, the script le until you find a comma and send the email, then read the q has after the comma and send also...
– Roger Regor