python-o365 icon indicating copy to clipboard operation
python-o365 copied to clipboard

Error Message: The token contains no permissions, or permissions can not be understood.

Open chatzich opened this issue 3 years ago • 1 comments

Hello I am using the above code


from O365 import Account
from O365.utils.token import FileSystemTokenBackend
tk = FileSystemTokenBackend(token_path=".", token_filename="o365_token.txt")

account = Account(('client_id', 'client_secret'), auth_flow_type = 'credentials', tenant_id="tenant_id") # tenant_id (required) available just below client_id in azure

if account.authenticate():
    print('Authenticated!')

mailbox = account.mailbox("[email protected]") # Your email (required) from which you want to send email (your app should have permission to this email)
m = mailbox.new_message()
m.to.add('[email protected]')
m.subject = 'Testing!'
m.body = "George Best quote: I've stopped drinking, but only while I'm asleep."
m.send()

with my corresponding client_id, client_secret and tenant_id but I am getting the following error

requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://graph.microsoft.com/v1.0/users/[email protected]/sendMail | Error Message: The token contains no permissions, or permissions can not be understood.

chatzich avatar May 05 '22 12:05 chatzich

Seems like you (the app) don't have permissions over the address provided to account.mailbox

alejcas avatar May 26 '22 14:05 alejcas