Home > Mobile >  Send Email From Google Sheets
Send Email From Google Sheets

Time:09-26

i want to write a script where I can send an email where the body will be the a cell value from the sheet

function sendemail()  {
MailApp.sendEmail("email address", "subject", "body");
}

the above code work but the only issue I'm facing to make "body" refer to the Cell from where data will be copied

CodePudding user response:

Here's a simple code you can try

function sendemail()  {
let ss = SpreadsheetApp.getActiveSpreadsheet();
let sh = ss.getSheetByName("the name of the sheet");

let emailbody = ss.getRange("").getValue();

MailApp.sendEmail("email address", "subject", emailbody);
}

Replace the "name of the sheet" with the actual name of the Sheet in your spreadsheet and insert the Cell reference to ss.getRange("") (Example: ss.getRange("A1")) to indicate the cell that has the message body you like GAS to use when sending the email.

This is considering that your script is bound to the Spreadsheet file. If if is not, then you have to manually call and store the Spreadsheet file before running any of the script above.

  • Related