如何解决Gmail API sendAsEmail 不是有效的用户或群组
我正在尝试使用 Gmail API 和 Google 管理员创建自定义“发件人”发送别名 (sendAsEmail):https://developers.google.com/gmail/api/reference/rest/v1/users.settings.sendAs/create
sendAsEmail is not a valid user or group
出现 400 错误。
在 Google Admin 中,我有 3 个经过验证的域,所有域都使用 MX 在 gmail 服务中正确注册:
@domain-a.com is primary domain
@domain-b.com (not a domain alias)
@domain-c.com (not a domain alias)
user@domain-a.com
是一个用户,没有定义发送别名。
当我创建 sendAsEmail user@domain-b.com
时,没问题。我可以看到它出现在 gmail 中。
当我创建 sendAsEmail user@domain-c.com
时,它失败了。我不知道为什么。如果我在 Google Admin 中搜索 user@domain-c.com
以确定它是否不是一个组,则没有结果。非常欢迎任何帮助。
我正在使用 PHP 进行 api 调用,但我不认为问题与语言有关。
解决方法
终于找到了解决办法。实际上有多个原因:
Google 管理员:
首先在 Google 管理员端,我必须创建一个别名:https://developers.google.com/admin-sdk/directory/v1/guides/manage-user-aliases。如果不这样做,Gmail sendAsEmail 创建将失败。请注意,用于执行此调用的客户端 HTTP 需要使用管理员用户:
<?php
putenv('GOOGLE_APPLICATION_CREDENTIALS=./client_secrets.json');
$this->client = new Google_Client();
$this->client->useApplicationDefaultCredentials(); // loads whats in that json service account file.
$this->client->setScopes([
Google_Service_Directory::ADMIN_DIRECTORY_USER,Google_Service_Directory::ADMIN_DIRECTORY_USER_SECURITY,Google_Service_Directory::ADMIN_DIRECTORY_USER_ALIAS
]);
$this->client->setSubject('admin@domain.com');
Gmail:
像这里解释的那样创建一个 sendAsEmail :https://developers.google.com/gmail/api/reference/rest/v1/users.settings.sendAs/create 请注意,用于执行此调用的 Client Http 需要模拟用户:
<?php
putenv('GOOGLE_APPLICATION_CREDENTIALS=./client_secrets.json');
$this->client = new Google_Client();
$this->client->useApplicationDefaultCredentials(); // loads whats in that json service account file.
$this->client->setScopes([
Google_Service_Gmail::GMAIL_SETTINGS_BASIC,Google_Service_Gmail::GMAIL_SETTINGS_SHARING
]);
$this->client->setSubject('user@domain.com');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。