3
votes

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: username@mydomain.com

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='username@mydomain.com', password='password'),
            auth_type=NTLM)

account = Account(primary_smtp_address='username@mydomain.com',
            config=config,
            access_type=DELEGATE)
1
check the accepted answer to: Connect to Exchange mailbox with Python, and also this one. Will these helped?Moinuddin Quadri
Yep been through these. I'm wondering if I have the username correct - I'm not sure what my "'MYWINDOMAIN\\myusername'" would be. I've tried the UPN without any luck!Phillip Watts

1 Answers

4
votes

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