python-o365
python-o365 copied to clipboard
Error Message: The token contains no permissions, or permissions can not be understood.
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.
Seems like you (the app) don't have permissions over the address provided to account.mailbox