Exchangelib office365 auth fail:无限循环

时间:2017-01-30 13:24:27

标签: python office365 exchangewebservices exchangelib

我正在尝试为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)

1 个答案:

答案 0 :(得分:2)

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

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

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