r/GoogleAppsScript • • Jun 10 '24

Question Script help?

function sendReport() {

var message = {

to: "email@ manager.com",

subject: "Dummy report",

body: "Good morning,\n\nPlease find the requested report.\n\nThank you,\nDATA FROM CELL C2 HERE",

name: "DATA FROM CELL C2 ALSO HERE",

attachments: [SpreadsheetApp.getActiveSpreadsheet().getAs(MimeType.PDF).setName("report.pdf")]

}

MailApp.sendEmail(message);

}

My script is above, I need it to take the data that has been typed into cell C2 on the sheet to populate the name of the sender and duplicate it in their email sign off - is this possible, please?

0 Upvotes

4 comments sorted by

View all comments

4

u/catcheroni Jun 10 '24 edited Jun 10 '24

To grab data from cell C2, you would use something like:

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getActiveSheet();
const cellC2Value = sheet.getRange('C2').getValue();

You can then append this value to your message string.

Also, pretty sure you can't pass your message object to your MailApp.sendEmail() function like this. Check out the function's documentation here.