Gmail Api send from alias

限于喜欢 提交于 2019-12-11 09:46:25

问题


I created a script that connects with the Gmail API using OAuth 2.0. It works perfectly, and I am able to send email from the authenticated account.

However, I can't send email from any of the account's aliases. If I try to do so I get the following error message:

    "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."
    }
}

I have verified that the alias is setup in Gmail and Google Apps.

Anyone have any ideas?


回答1:


Don't try to make the call as the alias (e.g. alias shouldn't be in the URL as the user ID), just put the alias email address in the "From" header in your sent message.

so in python would be something like:

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

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




回答2:


i found same error..

when i add user i use for sendmail on https://www.google.com/webmasters on domain i used, and on https://admin.google.com for API access

and now it's work..

hope this help..



来源:https://stackoverflow.com/questions/25485963/gmail-api-send-from-alias

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!