为单个 G Suite 电子邮件帐户获取“gmail.compose”权限以通过 GMail API 发送电子邮件

Obtaining `gmail.compose` privileges for single G Suite email account to send emails via GMail API

我正在尝试通过 GMail API 以编程方式撰写草稿,使用 this tutorial 和以下代码行:

service.users().drafts().create(userId=user_id, body=message).execute()

但我收到以下错误:

An error occurred: <HttpError 403 when requesting https://www.googleapis.com/gmail/v1/users/me/drafts?alt=json returned "Insufficient Permission">

请注意,使用 gmail.send 权限直接发送消息对我不起作用 - 我想

在 API 控制台中,我尝试启用以下范围 ../auth/gmail.compose,但有一条警告消息 Because you've added a sensitive scope, your consent screen requires verification by Google before it's published.

我已提交我的应用程序进行验证,但我刚刚收到一封电子邮件,指出 "We've extended the deadline to fully complete your verification from May 15th to June 26th, 2019"。

实际上,没有用户会使用我的 G Suite 电子邮件帐户(因此我的应用不能用于监视他们的消息),我只需要访问一个 单个 电子邮件帐户 info@example.com 向在 example.com 上使用我的网站的用户发送通知。

有没有什么方法可以使用我的密码在服务器端访问我的 info@example.com 帐户并以编程方式草拟消息,而无需经过冗长且不必要的应用程序验证过程?

事实证明,您可以拥有 "internal",而不是面向客户端的 "public" 应用程序,所有 GMail 范围都自动可用。

以下是 Google 团队的回复,其中描述了这些步骤(对我有用):

It appears your app is only used by the people in your domain.

If this is correct, please reply to this email to confirm that is the case. We will then reject your request so that you are able to update your project from public to internal.

In addition, you will need to associate your project with your organization by following the steps below:

If you have not already done so, create an Organization by following the Quickstart Using Organizations instructions.

Migrate the project into the organization you created as shown in Migrating Existing Projects into the Organization. Once you have associated your project with your organization, you and the project users in your organization can use the app to directly access OAuth scopes. No verification will be required.