无法为 Google Workspace 批量创建电子邮件别名

Can't create email aliases in bulk for Google Workspace

我有一个内置于 .NET 中的脚本,可以批量创建用户并创建别名。

用户是在 Google 管理控制台中创建的,但是它似乎没有完成电子邮件别名信息。检查管理控制台后,备用电子邮件字段为空白

这是错误信息:

Google.Apis.Requests.RequestError User creation is not complete. [412] Errors [Message[User creation is not complete.] Location[If-Match - header] Reason[conditionNotMet] Domain[global]]]

这是我的脚本:

// create new Gmail user                    
Google.Apis.Admin.Directory.directory_v1.Data.User newuserbody = new Google.Apis.Admin.Directory.directory_v1.Data.User();
UserName newusername = new UserName();
newuserbody.PrimaryEmail = userEmail;
newusername.GivenName = sFirst;
newusername.FamilyName = sLast;
newuserbody.Name = newusername;
newuserbody.Password = sPass;

Google.Apis.Admin.Directory.directory_v1.Data.User
user = service.Users.Insert(newuserbody).Execute();
user = null;
}

catch (Exception e) {
  LogMessage("CreateGoogleEmailApps", "Error", String.Format("Google user [{0}] could not be created at this time with error: {1}", sUN, e.Message));
}

try {
  // nickname attempt
  Alias newalias = new Alias();
  newalias.AliasValue = string.Format("username-{0}@{1}", sPass, ASAS_Create.Properties.Settings.Default.G_DOMAIN);
  Alias useralias = service.Users.Aliases.Insert(newalias, userEmail).Execute();
  newalias = null;
} catch (Exception e) {
  //LogMessage("CreateGoogleEmailApps", "Error", String.Format("Google user [{0}]'s alias could not be created at this time.", sUN));                    
  LogMessage("CreateGoogleAliasApps", "Error", string.Format("Google Alias Error for user [{0}] with error message[{1}].", sUN, e.Message));
}

经过一些测试,我发现了问题所在。

脚本正在向 Google 发出超过每分钟配额的请求,这就是创建用户而不是电子邮件别名的原因。

https://cloud.google.com/iot/docs/how-tos/exponential-backoff 中实施指数退避后,问题得到解决