0

I'm trying to update users of my domain to a new adress ,basically the same command than gam which is : " gam update user userx username mailadress@x.com "

My goal is to make the same thing but using google apps script, the documentation isn't very helpful because "AdminDirectory.Users.update(resource, userKey)" is even not present in it.

function updateUserName() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getActiveSheet();
var mailAdress= sheet.getRange(1, 1).getValue();

 var user = AdminDirectory.Users.get(colAdresseMail);

user.emails = [address='newtest@mydomainname.com', primary=true];

Logger.log(user);
 }

When I'm looking at logs, the address is now the new adress I want, but when I'm sending a mail to this adress, I have 2 mails , one with the mail I needed to have, and another mail delivery subsystem..

Maybe I forgot something?

Alex Bravo
  • 1,601
  • 2
  • 24
  • 40
jdris
  • 3
  • 2
  • I've solved my problem by adding var userup = AdminDirectory.Users.update(user, NewMailAdress); the new problem is now I can't receive mails from the old adress, when I'm updating username with google console or gam an alias is automatically created, here that's not the case, so I've tried user.aliases and adding the old adress as alias, but no mail received when using the old adress – jdris Dec 02 '15 at 10:50

1 Answers1

0

In the web UI, the alias is added automatically when you change an email address. Based on my previous work with this and the results you're seeing, I believe GAM does it programmatically (GETs original address and inserts it as an alias during the change) if you're seeing that behavior. You could check this in the source for GAM here if you'd like to be 100% sure.

You will need to use something like the following insert to set the alias like you've updated the email address in your comment:

AdminDirectory.Users.Aliases.insert(alias, email)

The documentation on this can be found here within the Directory API section of the Google Developers site.

miketreacy
  • 1,120
  • 1
  • 11
  • 17