简体   繁体   中英

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

I wanted to send the mail on Gmail from delegate account using python. 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.

How to send mail from Gmail delegate account using python?

I wanted to send the mail on Gmail from delegate account using python.

Delegation is preformed using service account authentication. For it to work it must be configured by the admin of your google workspace account

As I logged in using my primary email ID and password

Delegation can not be performed using a login and password. Nor can it be configured using a standard gmail account. It only works for google workspace domain accounts.

python delegation to service account

Note: create_delegated is the email address of the user on the workspace domain you would like the service account to delegate as.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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