Gmail Api从别名发送

Chi*_*iel 1 google-oauth gmail-api

我创建了一个使用OAuth 2.0与Gmail API连接的脚本.它工作正常,我可以从经过身份验证的帐户发送电子邮件.

但是,我无法从任何帐户的别名发送电子邮件.如果我尝试这样做,我收到以下错误消息:

    "error": {
    "errors": [
            {
                "domain": "global",
                "reason": "forbidden",
                "message": "[ACCOUNT] does not have privileges to [ALIAS] mailbox."
            }
        ],
    "code": 403,
    "message": "[ACOUNT] does not have privileges to [ALIAS] mailbox."
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经验证了别名是在Gmail和Google Apps中设置的.

有人有主意吗?

Eri*_*c D 7

不要尝试将调用作为别名(例如,别名不应作为用户ID在URL中),只需将别名电子邮件地址放在已发送邮件的"发件人"标题中即可.

所以在python中会是这样的:

email ="To:someone@example.com\r \nFrom:myalias@gmail.com\r \nSubject:blah\r \n\r \n \nUnbody goes here"

gmail.users().messages().send(userId ="me",body = {'raw':base64.urlsafe_b64encode(email)})