i got a spreadsheet with automatical (trigger) sending mail each day by pdf with this code :
function sendmail1() {
var email = "[email protected]";
var feuille = SpreadsheetApp.getActiveSpreadsheet();
var sujet = "Rapport journalier";
var corpsDuMessage = "<p>Bonjour,</p>Ci-joint rapport journalier d'hier.<p>Bonne journée.</p>";
var contenant = DriveApp.getFileById(feuille.getId()).getAs("application/pdf");
contenant.setName(feuille.getName() + ".pdf");
if (MailApp.getRemainingDailyQuota() > 0)
GmailApp.sendEmail(email, sujet, corpsDuMessage, {
htmlBody: corpsDuMessage,
attachments:[contenant]
});
}
i would like to set "sujet" adding a date in the cell A1. how ? and how to set the format ? don't want : Tue Sep 01 2020 00:00:00 GMT+0200 (heure d’été d’Europe centrale) i would like to have format YYYY-MM-DD 2020-09-01
thank your for your help
code2
function sendmail1() {
var email = "[email protected]";
var feuille = SpreadsheetApp.getActiveSpreadsheet();
var sujet = "Rapport journalier";
var corpsDuMessage = "<p>Bonjour,</p>Ci-joint rapport journalier d'hier.<p>Bonne journée.</p>";
var contenant = DriveApp.getFileById(feuille.getId()).getAs("application/pdf");
contenant.setName(feuille.getName() + ".pdf");
if (MailApp.getRemainingDailyQuota() > 0)
GmailApp.sendEmail(
email,
sujet +
Utilities.formatDate(
feuille
.getSheetByName('Sheet1')
.getRange('A1')
.getValue(),
feuille.getSpreadsheetTimeZone(),
'yyyy-MM-dd'
),
corpsDuMessage,
{/*....*/}
);
}
Use
Utilities.formatDate()
: