1

抱歉我的英语不太好:在 Windows 域中,我尝试使用 pypi 站点上给出的示例连接到我们的 exchangeserver (2010/SP3):

from exchangelib import DELEGATE, NTLM, Account, Credentials, Configuration
import os, logging

logging.basicConfig(level=logging.DEBUG)

creds = Credentials(
    username='mydomain\\my.name', 
    password='mypassword')

config = Configuration(server='exchange.xxx.local/EWS/Exchange.asmx', credentials=creds)

account = Account(
    primary_smtp_address='my.name@mycompany.com',
    credentials=creds,
    autodiscover=False,
    access_type=DELEGATE)

for item in account.inbox.all().order_by('-datetime_received')[:30]:
    print(item.subject, item.body, item.attachments)

启动脚本后,我在 python 控制台中得到以下输出:

DEBUG:exchangelib.protocol:Waiting for _protocol_cache_lock
DEBUG:exchangelib.protocol:Protocol __call__ cache miss. Adding key '('https://exchange.xxx.local/EWS/Exchange.asmx', Credentials('mydomain\\my.name', '********'), True)'
DEBUG:exchangelib.transport:Getting service auth type for https://exchange.xxx.local/EWS/Exchange.asmx
DEBUG:exchangelib.transport:Requesting b'<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><s:Header><t:RequestServerVersion Version="Exchange2016" /></s:Header><s:Body><m:ResolveNames ReturnFullContactData="false"><m:UnresolvedEntry>mydomain\\my.name</m:UnresolvedEntry></m:ResolveNames></s:Body></s:Envelope>' from https://exchange.xxx.local/EWS/Exchange.asmx
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): exchange.xxx.local
Traceback (most recent call last):
  File "C:\CWS\Python-venv\p353-01\lib\site-packages\urllib3\connectionpool.py", line 594, in urlopen
self._prepare_proxy(conn)
  File "C:\CWS\Python-venv\p353-01\lib\site-packages\urllib3\connectionpool.py", line 810, in _prepare_proxy
conn.connect()
  File "C:\CWS\Python-venv\p353-01\lib\site-packages\urllib3\connection.py", line 294, in connect
self._tunnel()
  File "C:\seProg\python353\Lib\http\client.py", line 832, in _tunnel
message.strip()))
OSError: Tunnel connection failed: 407 Proxy Access Denied    
... (and many more lines with error messages)

我还使用 autodiscover=True 尝试了 exchangelib 站点中的其他选项,并且只给出了 creds=(没有 config=)。没有成功。然后我从https://ewseditor.codeplex.com/安装了 EWS-Editor,以查看通过 EWS 的连接是否可以在我公司的环境中工作。它与那个工具配合得很好,只需给它我的 SMTP 地址。

我将非常感谢任何帮助。提前致谢!

4

1 回答 1

0

您可能需要告诉 exchangelib 您的代理。您可以通过环境变量:https ://github.com/ecederstrand/exchangelib/issues/123#issuecomment-295648189或通过自定义 HTTPAdapter 类:https ://github.com/ecederstrand/exchangelib/issues/156#问题comment-312391095

于 2017-07-10T21:33:57.457 回答