I have a Python script that is reading Office 365 emails and downloading attachments. I am using exchangelib and trying to switch from Basic Authentication to OAUTH2.
My old script was authenticating without any issues:
from exchangelib import Credentials, Account
username = '[email protected]'
pwd = '123456'
credentials = Credentials(username, pwd)
account = Account(username,
credentials=credentials, autodiscover=True)
The new one one:
from exchangelib import OAuth2Credentials
username = '[email protected]'
tenant_id = 'TENANT ID'
client_id = 'CLIENT ID'
secret_value = 'CLIENT SECRET'
credentials = OAuth2Credentials(client_id=client_id, client_secret=secret_value, tenant_id=tenant_id)
account = Account(username,
credentials=credentials, autodiscover=True)
The new script returns an error:
exchangelib.errors.ErrorNonExistentMailbox: The SMTP address has no mailbox associated with it
I have created and registered app in Azure portal. Email/User is added to app.



