Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gmail Api send from alias

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?

like image 437
Chiel Avatar asked Aug 31 '26 21:08

Chiel


1 Answers

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: [email protected]\r\nFrom: [email protected]\r\nSubject: blah\r\n\r\nbody goes here"

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

like image 175
Eric D Avatar answered Sep 04 '26 15:09

Eric D



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!