The entire code is posted at the bottom of this email but the code in questions is as follows.
function sendEmail_(pdf) {
var month = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();
var coachName = " CoachName ";
var pdfName = (coachName + month + " 2022 Mileage");
var attachment = pdf.setName(pdfName);
GmailApp.sendEmail('
em...@email.com',
coachName + month + " Mileage",
coachName + " Mileage for " + month + " 2022" + '\n\n', {
attachments: [attachment]
});
}
I am wanting the pdf attachment to be named "CoachName month Mileage 2022". When the script runs, the email sends properly, but the attachment is named "mail attachment". Is there a simple way to get the attached file renamed when I send it? Thanks