简体   繁体   English

如何使用 Python 从 Gmail 代表账户发送 Email?

[英]How to send an Email from Gmail Delegate Account using Python?

I wanted to send the mail on Gmail from delegate account using python.我想使用 python 从委托帐户发送 Gmail 上的邮件。 As I logged in using my primary email ID and password, so the python script send the mail from my primary account instead of Delegate account.当我使用我的主 email ID 和密码登录时,python 脚本从我的主帐户而不是委托帐户发送邮件。

How to send mail from Gmail delegate account using python?如何使用 python 从 Gmail 委托帐户发送邮件?

I wanted to send the mail on Gmail from delegate account using python.我想使用 python 从委托帐户发送 Gmail 上的邮件。

Delegation is preformed using service account authentication.使用服务帐户身份验证执行委派 For it to work it must be configured by the admin of your google workspace account要使其正常工作,必须由您的 google 工作区帐户的管理员配置

As I logged in using my primary email ID and password当我使用我的主 email ID 和密码登录时

Delegation can not be performed using a login and password.无法使用登录名和密码执行委派。 Nor can it be configured using a standard gmail account.也不能使用标准的 gmail 帐户进行配置。 It only works for google workspace domain accounts.它仅适用于谷歌工作区域帐户。

python delegation to service account python 委托给服务帐户

Note: create_delegated is the email address of the user on the workspace domain you would like the service account to delegate as.注意:create_delegated 是您希望服务帐户委托为的工作区域中用户的 email 地址。

credentials = ServiceAccountCredentials.from_p12_keyfile(
        SERVICE_ACCOUNT_EMAIL,
        SERVICE_ACCOUNT_PKCS12_FILE_PATH,
        'notasecret',
        scopes=['https://www.googleapis.com/auth/gmail.send'])

    credentials = credentials.create_delegated(user_email)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM