Trying to read emails from webmail using exchangelib

72 Views Asked by At

I am trying to read the emails from my Webmail account but end up getting the following error:

"name": "MalformedResponseError", "message": "Unknown failure in response. Code: 404 headers: {'Date': 'Fri, 14 Jul 2023 10:41:23 GMT', 'Server': 'Apache', 'X-Powered-By': 'PHP/8.1.18', 'Pragma': 'no-cache', 'Expires': 'Wed, 11 Jan 1984 05:00:00 GMT', 'Cache-Control': 'no-cache, must-revalidate, max-age=0',

This is the code I tried is as below.

from exchangelib import Account,Credentials,Configuration,DELEGATE 
import time
from exchangelib import EWSDate, EWSDateTime
from exchangelib.protocol import BaseProtocol, NoVerifyHTTPAdapter
BaseProtocol.HTTP_ADAPTER_CLS = NoVerifyHTTPAdapter

def connect_mail(username, password, address):
    credentials = Credentials(username=username, password=password)
    config = Configuration(server='mail.xxxx.com', credentials=credentials,auth_type='NTLM')
    account = Account(address,credentials=credentials,autodiscover=False,config=config, access_type=DELEGATE)
return account

username = "[email protected]"
password = "xxxxxxxxxx"
address = "[email protected]"
account = connect_mail(username, password, address)
1

There are 1 best solutions below

0
Erik Cederstrand On

The server you specified does not host the EWS API. You need to contact your Exchange server admins to get the correct address, or use autodiscover to get the server automatically.