gmail - Gmail API sendAsEmail 不是有效的用户或组
问题描述
我正在尝试使用 Gmail API 和 Google 管理员创建自定义“发件人”发送别名 (sendAsEmail):https ://developers.google.com/gmail/api/reference/rest/v1/users.settings.sendAs /创造
我收到 400 错误sendAsEmail is not a valid user or group
。
在 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
是一个用户,没有定义 send-as 别名。当我创建 sendAsEmail 时user@domain-b.com
,没有问题。我可以看到它出现在 gmail 中。当我创建 sendAsEmailuser@domain-c.com
时,它失败了。我不知道为什么。如果我user@domain-c.com
在 Google Admin 中搜索以确保它不是一个组,则没有结果。任何帮助都会非常受欢迎。
我正在使用 PHP 进行 api 调用,但我认为问题与语言无关。
解决方案
终于找到了解决办法。实际上有多种原因:
谷歌管理员:
首先在 Google Admin 方面,我必须创建一个别名: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');
邮箱:
创建一个 sendAsEmail,如下所述:https://developers.google.com/gmail/api/reference/rest/v1/users.settings.sendAs/create 请注意,用于执行此调用的客户端 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');
推荐阅读
- php - 如何修复 - 502 错误网关
- c++ - 对 C++ 列表的基于索引的访问
- python - 强制所有行在条件后取值
- java - 使用有状态会话的 Drool 实现内存不足
- android - 有没有办法只在 Android 中使用 GoogleMaps API 来收听平底锅?
- r - 在模块中使用 addPopover
- google-analytics - BigQuery:基于最近的时间戳加入
- android - 重载的 dispatchKeyEvent 方法在其中添加一些后处理代码时冻结应用程序
- docker - 复制名为“run”的文件后出现 Docker 错误
- java - 拿第一项不完成