Home > OS >  Need to send an Email(dynamic email address) when the checkbox is checked(True)
Need to send an Email(dynamic email address) when the checkbox is checked(True)

Time:04-04

Need to send an email when the checkbox is checked to TRUE. For email body having the value in cell C6 and C8 and recipient email address in C7(dynamic and will change as per the user).

I tired " MailApp.sendEmail(emailAddress, subject, message); ", however I failed.

I failed to get the data from the said cells and send it as a message on the recipient's email address.

CodePudding user response:

Hey you might want to assign the variables with a getRange('C7').getValue() from each of the cell. I have tested using the sample have made the message to include the assign to name and SRF number with the sample code below.

enter image description here

function sendemail(){
  const ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SRF Allotment");
  const emailAddress = ss.getRange("C7").getValue();
  const name = ss.getRange("C8").getValue();
  const srf = ss.getRange("C6").getValue();
  const subject = "Email Subject";
  const message = "Hey "    name   ",\n\n"   "Please find the SRF: "   srf   " assigned to you.";

  MailApp.sendEmail(emailAddress,subject,message);
}

Would also recommend adding a button UI in your spreadsheet so you may send the email with a button on your Spreadsheet ribbon.

Reference: https://developers.google.com/apps-script/reference/base/menu

  • Related