0

I am using goodle gmail send API for sending the mails.

POST https://www.googleapis.com/gmail/v1/users/me/messages/send?key=[My_API_KEY]

Authorization: Bearer [ACCESS_TOKEN]
Accept: application/json
Content-Type: application/json

{
  "raw": "SGkgVGVhbSwKVGVzdGluZyBFbWFpbCBBdXRoZW50aWNhdGlvbgoKCgoK"
}

When I am executing this I am getting an error like:

{
    "error": {
        "errors": [
            {
                "domain": "global",
                "reason": "forbidden",
                "message": "Delegation denied for mymailaddress@example.com"
            }
        ],
        "code": 403,
        "message": "Delegation denied for mymailaddress@example.com"
    }
}

Could anyone help me on this. Thank you in advance.

carlesgg97
  • 4,184
  • 1
  • 8
  • 24
sirisha
  • 1
  • 1
  • Possible duplicate of [Gmail API returns 403 error code and "Delegation denied for "](https://stackoverflow.com/questions/26135310/gmail-api-returns-403-error-code-and-delegation-denied-for-user-email). Kindly let me know if the answer proposed there works for you. – carlesgg97 Nov 18 '19 at 11:37

1 Answers1

0

Try these-

1. best thing to do is to just always have ' userId="me" ' in your requests. That tells the API to just use the authenticated user's mailbox--no need to rely on email addresses.

2. The access token and other parameters present in JSON are not associated with new email id/account. So, in order make it run you just have to delete the '.credentails' folder and run the program again. Now, the program opens the browser and asks you to give permissions.
To delete the folder containing files in python

import shutil
shutil.rmtree("path of the folder to be deleted")

you may add this at the end of the program

Rishit Dagli
  • 1,000
  • 8
  • 20