问题
I have a user with aliases. In admin.google.com I can view all the aliases, but when with that user, I create a Google Apps Script with only this code:
var aliases = GmailApp.getAliases();
Logger.log(aliases);
The log is empty: "[]".
I try to create the script also with an Super Admin User and Admin Directory API enabled but the result is the same. I need this method to send email like this:
GmailApp.sendEmail(email , "Subj.. ", "body....", {from: aliases[0]});
Why isn't this working?
回答1:
There are account aliases for a Google Apps domain (e.g. Business, Education), which are for authentication during login to Google Apps.
There are also account aliases for GMail, which are separate from the Google Apps account aliases. These are the aliases that would show up when you call GmailApp.getAliases()
.
回答2:
You need to log in to you gmail account, go to settings, and then Accounts. Here you add the alias that you have set up in admin.google.com. Click on "Add another email account that you own", and in the popup-window add the alias you created. Now the new alias will be listed in getAliases(), and can be used as from-address in the options of GmailApp.sendEmail().
One cool thing: this also works if you remove your alias in admin.google.com, and then add it as a group-address instead. Then set this as your alias (this proved useful for me)
来源:https://stackoverflow.com/questions/32480051/gmailapp-getaliases-returns-a-blank-list