GmailApp.getAliases() returns a blank list

狂风中的少年 提交于 2021-01-27 14:31:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!