如何使用exchangelib连接到使用Outlook Web AppOWA的工作电子邮件?

问题描述

我目前正在尝试找到通过一种语言连接到我的工作电子邮件的方法,而python似乎正在寻找一个库。我找到了exchangelib库,但是它有点旧,而且找不到其他任何东西可以连接到Exchange Server(我的工作电子邮件不是“ @ outlook.com”)。

我找到了我的用户名(“ WORD \ username”),并且知道了我的电子邮件,密码和Outlook Web App电子邮件的URL(“ www.company.net”)

0 16 * * 1,3,5

这应该只是打印我收到的电子邮件,但由于主机无法响应,我似乎无法连接

start_date

我尝试将完整的url用于我的OWA电子邮件,而改用exchangelib service_endpoint参数

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'))

有什么我想念的吗?可能是因为我公司的安全功能吗?我不确定如何正确执行此操作。

解决方法

exchangelib使用EWS连接到Exchange服务器。 OWA只是Exchange的基于Web的客户端。您无法以编程方式连接到它。尽管如此,您的服务器仍然完全有可能连接到EWS端点。

您需要启用自动发现功能以自动找到EWS终结点,或者向Exchange服务器管理员询问EWS的正确终结点。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...