【发布时间】:2020-09-23 16:00:29
【问题描述】:
我目前正在尝试寻找通过一种语言连接到我的工作电子邮件的方法,python 似乎有一个我正在寻找的库。我找到了 exchangelib 库,但它有点旧,我找不到任何其他东西可以连接到 Exchange 服务器(我的工作电子邮件不是“@outlook.com”)。
我找到了我的用户名(“WORD\username”),并且我知道我的电子邮件、密码和 Outlook Web 应用电子邮件的 URL(“www.company.net”)
from exchangelib import Account, Configuration, Credentials, DELEGATE, Folder
def connect(SERVER, EMAIL, USERNAME, PASSWORD):
"""
Get Exchange account cconnection with server
"""
creds = Credentials(username=USERNAME, password=PASSWORD)
config = Configuration(server=SERVER, credentials=creds)
account = Account(primary_smtp_address=EMAIL, config=config, autodiscover=False, access_type=DELEGATE)
for item in account.inbox.all().order_by('-datetime_received')[:2]:
print(item.subject, item.body, item.attachments)
def main():
print(connect("www.company.net",
"my@email.net", "WORD\\username", "password"))
这只是为了打印我的电子邮件,但我似乎无法连接,因为主机没有回复
Failed to create cached protocol with key ('https://www.company.net/EWS/Exchange.asmx', Credentials('WORD\\username', '********')): HTTPSConnectionPool(host='www.company.net', port=443): Max retries exceeded with url: /EWS/Exchange.asmx (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000169BAF68FD0>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))
我尝试使用我的 OWA 电子邮件的完整 url 并改用 exchangelib service_endpoint 参数
def connect(SERVER, EMAIL, USERNAME, PASSWORD):
"""
Get Exchange account cconnection with server
"""
creds = Credentials(username=USERNAME, password=PASSWORD)
config = Configuration(service_endpoint=SERVER, credentials=creds)
account = Account(primary_smtp_address=EMAIL, config=config, autodiscover=False, access_type=DELEGATE)
for item in account.inbox.all().order_by('-datetime_received')[:2]:
print(item.subject, item.body, item.attachments)
但获取授权类型失败
Failed to create cached protocol with key ('https://company.net/.../.../', Credentials('WORD\\username', '********')): Failed to get auth type from service
我有什么遗漏吗?可能是因为我公司的安全功能吗?我不确定如何正确执行此操作。
【问题讨论】:
标签: python python-3.x email exchangewebservices exchangelib