Can I change the address using sendEmail?

I am wondering if there are any options for changing the FROM address of an email sent using MailApp.sendEmail.

I created a form published as a web application. Students fill out and submit the form and receive an email. I see how to change the email response to the sender address and name. I know that the email address using my address as the From address, since I am the owner of the script, and the application works like me.

Is there a way to establish that the From address belongs to another person, in this case, the instructor? I guess one way to achieve this is to make it the owner of the script and pass it through re-publishing the application for us, but I would not refuse to pass it to him. (From what I saw, the owner of the script can publish the script.)

In other words, I want the From address to represent the client for which the script is being created, and not the programmer who writes it.

I understand that this is not a desirable feature that allows a script to send email from anyone under the sun. I'm just wondering if anyone has any recommendations on how to solve my problem.

Thanks!

+11
source share
5 answers

Google is not flexible in this regard - the only "from" address that you see is the one that belongs to the user whose authority is controlled by the script.

Instead of working as a "programmer," you can use the Google account "robot", something like DepartmentRobot@ourdomain.com . You can develop your scripts as yourself, and then republish them from the robot.

In the Google Apps domain, an administrator can create this pseudo user and edit the settings to hide them from the Google Apps directory, if desired.

The letter students receive will not be from their instructor, but it will also not be from you.

+3
source

If you use GMailApp.sendMail (instead of MailApp.sendEmail), you can specify it as an additional optional parameter: https://developers.google.com/apps-script/reference/gmail/gmail-app#sendEmail(String,String, String, Object)

I believe that you can only specify the aliases with which you have already set up your Gmail account.

+11
source

Yes, you can and it is quite easy. Use the log to determine what place your alias has in the array if you have multiple aliases. Then, to verify that you have the correct array location, use this in the log.

 var aliases = GmailApp.getAliases() Logger.log(aliases); //returns the list of aliases you own Logger.log(aliases[0]); //returns the alias located at position 0 of the aliases array GmailApp.sendEmail(' person@aol.com ','From an alias', 'A message from an alias!', {'from': aliases[0]}); 
+5
source

I wanted to build on chrisb to answer above , but I have not yet been allowed to comment ...

As chrisb said:

  • create an alias in your account for the form only.
  • Use Gmail.App to send email "from" the alias you created.

Then write a Google Apps script to process emails sent to this alias so that the instructor emails appear in your inbox, but emails from anyone else are sent to the instructor with the "replyTo" field set for the one who sent the email .

0
source

this is only possible if you add an alias to the account with which you want to send mail.

important: the alias must be added manuelly to the desired account (in Gmail, go to "settings", then "Account", then "Send as")

when you do this, you should use the GmailApp method in your script called "GmailApp.SendEmail ()"

First you need to read the alias from your Gmail account:

var myAliases = GmailApp.getAliases(); Suppose you have only one alias, so the first alias will be in indexd 0 → myAliases[0] in which case you can use this method as follows:

 GmailApp.sendEmail(' recipient@yourdomain.con ', 'subject', 'body', {from: myAliases[0], name:'Name of the Alias'}); 

this is.

0
source

All Articles