1
votes

I'm currently using this function in my google open sheets script ...

MailApp.sendEmail(emailAddress,emailAddress, subject, body);

The problem is that I can't control the from email address. Where does the from email get set at ? I can control the reply email address but that doesn't really address my problem.

Any thoughts ? Thanks!

1

1 Answers

0
votes

This question is more complex because you have both MailApp (Which you are using), and GmailApp (Which you are not, but can be used similarly to send mail).

The structure for the .sendEmail function is actually .sendEmail(recipient, subject, body, options), with options providing you the ability to modify things such as the 'from' address.

For the MailApp, you are not able to modify the from address, it's not one of the options. Speculating on the reasons for this are straightforward enough (Spammers would love scripts that allowed them to send mail from any email address they wanted), but pointless.

For the GmailApp, you can specify your from address as one of the options, but this is restricted to only selecting alias addresses from the GMail account currently running the script. You can do it in this format:

 // Send an email specifying a from address
 GmailApp.sendEmail('[email protected]', 'Subject example', 'This is the body of the message', {
     from: '[email protected]', //Specify a from address, must be an alias of the sending account
     name: 'John Doe'//Specify my name if I want
 });

Note: Using this requires the user running the script to grant extra permissions I think.