Search code examples
pythonexchangewebservicesoutlook-web-app

Authorization error connecting to Exchange with exchangelib


I've been trying for some time now to connect to Outlook mailbox exchange using Python EWS client.

Problem is, I keep getting 401 authorisation errors when I connect.

I can successfully access the account on my browser via OWA by going to https://webmail.mydomain.com and logging in using some of the details below. But I've tried almost every permutation of user names, UPN etc, using autodiscover etc in my script but no luck :-( Any help would be greatly appreciated. p.s Merry Xmas :-)

Email: [email protected]

UserName: username

Password: password

server: webmail.mydomain.com

from exchangelib import DELEGATE, IMPERSONATION, Account, Credentials, \
    EWSDateTime, EWSTimeZone, Configuration, NTLM, CalendarItem, Message, \
    Mailbox, Q
from exchangelib.folders import Calendar, ExtendedProperty, FileAttachment, ItemAttachment, \
    HTMLBody

config = Configuration( server='webmail.mydomain.com',
            credentials=Credentials(username='[email protected]', password='password'),
            auth_type=NTLM)

account = Account(primary_smtp_address='[email protected]',
            config=config,
            access_type=DELEGATE)

Solution

  • I had been told an incorrect MYWINDOMAIN. Used the correct one and it worked!