0

我正在尝试为 Office365 配置 python exchangelib,但不知何故它不起作用,不确定是因为公司防火墙还是配置错误。

我已经尝试了 40 多个配置,有和没有自动发现链接。

我正在尝试连接到组邮箱而不是私人邮件帐户。

代码:

from exchangelib import DELEGATE, Account, Credentials, IMPERSONATION, EWSDateTime, EWSTimeZone, Configuration, NTLM, CalendarItem, Message, Mailbox, Attendee, Q
from exchangelib.folders import ExtendedProperty, FileAttachment, ItemAttachment, HTMLBody
import logging
config = Configuration(
#service_endpoint='https://triedthisservertoo.com/EWS/Exchange.asmx', 
    server='localSMTPserver',
    credentials = Credentials(
    username='x@xx.com',
    password='topsecret'),
    auth_type=NTLM,
    verify_ssl=False
    )

account = Account(
    primary_smtp_address='x@xx.com',
    autodiscover=False, 
    config=config,
    access_type=IMPERSONATION)

logging.basicConfig(level=logging.DEBUG)
pprint (account.folders())

输出(显然是无限循环):

C:\Users\mcindea\Downloads\dist\exchangelib-1.7.6>python test.py
C:\Users\mcindea\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\packages\urllib3\connectionpool.py:852: InsecureRequestWarning: Unverified HTTPS request is being made. Adding c InsecureRequestWarning)
C:\Users\mcindea\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\packages\urllib3\connectionpool.py:852: InsecureRequestWarning: Unverified HTTPS request is being made. Adding c  InsecureRequestWarning)
C:\Users\mcindea\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\packages\urllib3\connectionpool.py:852: InsecureRequestWarning: Unverified HTTPS request is being made. Adding c  InsecureRequestWarning)
4

1 回答 1

2

找到了答案,这是 MS 用来创建我们帐户的愚蠢配置。用户名必须采用 user.name@on.company.com 格式。

我忘记了“on”子域。如果有人需要脚本(按主题在 Exchange 服务器中搜索电子邮件,并将附件保存在本地),可以在此处找到:

https://github.com/psychameleon/Office365GrabMail/blob/master/email-grabber.py

于 2017-01-30T14:47:04.027 回答