Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email via Google Apps Script from another email address

I'm familiar with how to send emails via Google Apps Script (http://code.google.com/googleapps/appsscript/articles/sending_emails.html). It's super cool. But is there a way I can email from Apps Script from another email address that I have access to? It seems like I can specify a reply to address, but the user still sees the email as from my primary user account, I believe.

Example: My email is [email protected], but I'd like to send the email from [email protected] from the Apps Script Javascript.

Thanks for any advice.

like image 763
Garen Checkley Avatar asked Oct 24 '11 23:10

Garen Checkley


People also ask

Does Gmail have email scripting?

If you know JavaScript, you can use Google Apps Script to add features to many Google products including Gmail. If you've used Office scripting, the idea is the same, although obviously the implementation is very different.


2 Answers

The only way to achieve that is by logging with the account of desired email, in your case "[email protected]" and run the script with it. If you're running the script automatically via a trigger, just set the trigger with this account. If you do not have an account for it, you'd have to create one.

Adjusting the from field is not possible. There's an open issue about this on Apps Script tracker: Issue 172: Ability to send email from users different accounts ("from:" field in gmail)

--update: as one can see by following the link above, this is now possible if the desired address is an alias in your gmail.

like image 159
Henrique G. Abreu Avatar answered Sep 20 '22 17:09

Henrique G. Abreu


Try this

var alias=GmailApp.getAliases();//This gets array of Aliases set up in gmail.
GmailApp.sendEmail(email , "Subj.. ", "body....", {from: alias[0]}); //Uses first alias
like image 43
Waqar Ahmed Shujrah Avatar answered Sep 21 '22 17:09

Waqar Ahmed Shujrah