Home > Blockchain >  Is it possible to change "sender email" in sendEmail?
Is it possible to change "sender email" in sendEmail?

Time:10-08

I am currently working on a script that sends email to the user if the excel has been updated. I am able to send the email. However, when testing, I notice that the "sender" email is my email. I would like to change the "sender" email to another email ("[email protected]"). How can I achieve it if possible? I would like to do this as it will be a google add-on (as in you will be able to install the addon on Google Forms, Spreadsheet, etc.). If it can not be done using MailApp or GmailApp, what is an alternative?

 function sendEmail(e){
  var email = HtmlService.createTemplateFromFile("email.html");
  var htmlText = email.evaluate().getContent();

  Logger.log(htmlText);

  var emailTo = e.response.getRespondentEmail();
  //var emailFrom = '[email protected]'

  var subject = "Lorem ipsum dolor sit amet"
  var textBody = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
  var options = { htmlBody: htmlText };

  if(emailTo !== undefined){
   GmailApp.sendEmail(emailTo, subject, textBody, options);
  }
}

CodePudding user response:

You need to create an alias first to do that. Complete the steps on the link.

Once an alias is created, confirm if it is being returned when calling GmailApp.getAliases()

Upon confirmation, you can now use it on the from parameter under advanced parameters.

the address that the email should be sent from, which must be one of the values returned by getAliases()

Reference:

  • Related