A Problem of Using Python to Link to Local Exhcnage Server EWS
linseasea opened this issue · 4 comments
Exchange Server Type: Local
Operating system: macOS
Python version: 3.11
Library used: exchangelib 3.3.0
Exchange Server Version: Exchange 2016
The link information I have:
-
Exchange server local administrator account and password
-
The IP address of the exchange server
-
Email account for company domain name
Action taken:
- I'm trying to open it https://mycommanymail.com/ews/exchange.asmx And successfully logged in.
My script:
from exchangelib import DELEGATE, Account, Credentials
credentials = Credentials(
username='172.19.32.12\admin', # Or me@example.com for O365
password='co00kewq#9'
)
a = Account(
primary_smtp_address='lucius@company.com',
credentials=credentials,
autodiscover=True,
access_type=DELEGATE
)
Print first 100 inbox messages in reverse order
for item in a.inbox.all().only('subject').order_by('-datetime_received')[:100]:
print(item.subject)
My error info:
/usr/local/bin/python3 /Users/lin/Desktop/code/Task/V0.3-0911/exchange.py
lin@linbaicaideMacBook-Pro Task % /usr/local/bin/python3 /Users/lin/Desktop/code/Task/V0.3-0911/exchange.py
Traceback (most recent call last):
File "/Users/lin/Desktop/code/Task/V0.3-0911/exchange.py", line 7, in
a = Account(
^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/exchangelib/account.py", line 167, in init
).discover()
^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/exchangelib/autodiscover/discovery.py", line 124, in discover
ad = self._step_1(hostname=domain)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/exchangelib/autodiscover/discovery.py", line 336, in _step_1
return self._step_2(hostname=hostname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/exchangelib/autodiscover/discovery.py", line 352, in _step_2
return self._step_3(hostname=hostname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/exchangelib/autodiscover/discovery.py", line 388, in _step_3
return self._step_4(hostname=hostname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/exchangelib/autodiscover/discovery.py", line 415, in _step_4
return self._step_6()
^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/exchangelib/autodiscover/discovery.py", line 467, in _step_6
raise AutoDiscoverFailed(
exchangelib.errors.AutoDiscoverFailed: All steps in the autodiscover protocol failed for email lucius@company.com. If you think this is an error, consider doing an official test at https://testconnectivity.microsoft.com
lin@linbaicaideMacBook-Pro Task %
If you already know the hostname og the Exchange server, then there's no need to use autodiscover.
New code:
from exchangelib import DELEGATE, Account, Credentials
credentials = Credentials(
username='172.19.32.12\admin', # Or me@example.com for O365
password='co00kewq#9'
)
a = Account(
primary_smtp_address='lucius@company.com',
credentials=credentials,
autodiscover=False,
access_type=DELEGATE
)
New error:
lin@linbaicaideMacBook-Pro Task % /usr/local/bin/python3 /Users/lin/Desktop/code/Task/V0.3-0911/exchange.py
Traceback (most recent call last):
File "/Users/lin/Desktop/code/Task/V0.3-0911/exchange.py", line 7, in
a = Account(
^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/exchangelib/account.py", line 177, in init
raise AttributeError("non-autodiscover requires a config")
AttributeError: non-autodiscover requires a config
lin@linbaicaideMacBook-Pro Task %
Please read the docs on creating a connection without autodiscover: https://ecederstrand.github.io/exchangelib/#optimizing-connections
Closing as I don't think this is an issue with exchangelib.