0

I'm trying to connect to Microsoft Exchange web server using Python and the exchangelib library. Here is my code (with edited domain, username, password and SMTP server):

from exchangelib import DELEGATE, Configuration, Credentials, Account

credentials = Credentials('MyDomain\\me@somewhere.co.uk', 'password')

config = Configuration(server='10.10.10.10', credentials=credentials)

account = Account('me@somewhere.co.uk', credentials=credentials, config=config, autodiscover=False, access_type=DELEGATE)

Trying to initiate the Account object throws this error:

Failed to create cached protocol with key ('https://10.10.10.10/EWS/Exchange.asmx', 

Credentials('MyDomain\\me@somewhere.co.uk', '********')): HTTPSConnectionPool(host='10.10.10.10', port=443): Max retries exceeded with url: /EWS/Exchange.asmx (Caused by SSLError(SSLError("bad handshake: SysCallError(10054, 'WSAECONNRESET')")))
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\cached_property.py", line 69, in __get__
    return obj_dict[name]
KeyError: 'protocol'

What causes this error, and how do I fix it? Thank you.

Typeset
  • 26
  • 6

1 Answers1

0

exchangelib cannot use the SMTP protocol. It uses EWS (Exchange Web Services).

You can either ask your Exchange admins for the EWS endpoint, or use autodiscover to get it automatically, if autodiscover has been set up for your domain.

Erik Cederstrand
  • 9,643
  • 8
  • 39
  • 63
  • The error you have in the stack trace is due to validation errors with the SSL certificate on the endpoint. There are various options for dealing with this described in the README for exchangelib. – Erik Cederstrand Dec 16 '19 at 11:39