用于与内部部署和Office 365 Exchange Web服务交互的Python包
py-ews的Python项目详细描述
py ews
.______ ____ ____ ___________ __ ____ _______.
| _ \ \ \ / / | ____\ \ / \ / / / |
| |_) | \ \/ / ______| |__ \ \/ \/ / | (----`
| ___/ \_ _/ |______| __| \ / \ \
| | | | | |____ \ /\ / .----) |
| _| |__| |_______| \__/ \__/ |_______/
与exchange web服务交互的python包
py ews是一个跨平台的python包,可与Exchange 2010到2019内部部署和Exchange Online(Office 365)进行交互。此包将包装所有exchange web服务终结点,但当前重点是提供eDiscovery终结点。
py ews在当前版本中具有以下显著功能:
- 自动发现支持
- 授权支持
- 模拟支持
- 根据提供的凭据检索所有可以搜索的邮箱
- 使用所有支持的搜索属性在Exchange环境中搜索邮箱列表(或单个邮箱)
- 从Exchange环境中的邮箱中删除电子邮件项目
- 检索特定帐户的邮箱收件箱规则
当前此包支持以下服务终结点:
- 自动发现
- 删除项目
- getInboxRules
- GetSearchableMailboxes
- 解析名称
- 搜索邮箱
安装
OS X和Linux:
pip install py-ews
窗口:
pip install py-ews
用法示例
使用py ews的第一步是需要创建一个UserConfiguration
对象。将其视为exchange web服务的所有连接信息。使用office 365创建UserConfiguration object
的示例是:
frompyewsimportUserConfigurationuserconfig=UserConfiguration('myaccount@company.com','Password1234')
如果您想使用替代的Autodiscover
端点(或任何替代端点),请使用endpoint
命名参数提供一个:
frompyewsimportUserConfigurationuserconfig=UserConfiguration('myaccount@company.com','Password1234',endpoint='https://outlook.office365.com/autodiscover/autodiscover.svc')
有关创建UserConfiguration
对象的更多信息,请参阅readthedocs页面上的完整文档。
既然有了UserConfiguration
对象,现在可以使用ServiceEndpoint
。此示例将演示如何使用GetSearchableMailboxes
EWS终结点来标识您有权访问的邮箱。
一旦确定了邮箱引用ID列表,就可以使用SearchMailboxes
EWS端点开始搜索所有这些邮箱。
然后,将使用DeleteItem
EWS终结点从Exchange中删除返回的结果(移动到“已删除邮件”文件夹)。
frompyewsimportUserConfigurationuserconfig=UserConfiguration('myaccount@company.com','Password1234')# get searchable mailboxes based on your accounts permissionsreferenceid_list=[]formailboxinGetSearchableMailboxes(userconfig).response:referenceid_list.append(mailbox['ReferenceId'])# let's search all the referenceid_list itemsmessages_found=[]forsearchinSearchMailboxes('subject:account',userconfig,referenceid_list).response:messages_found.append(search['MessageId'])# we can print the results first if we wantprint(search['Subject'])print(search['MessageId'])print(search['Sender'])print(search['ToRecipients'])print(search['CreatedTime'])print(search['ReceivedTime'])#etc.# if we wanted to now delete a specific message then we would call the DeleteItem # class like this but we can also pass in the entire messages_found listdeleted_message_response=DeleteItem(messages_found[2],userconfig).responseprint(deleted_message_response)
以下是调用上述代码时返回的输出示例:
YOUR ACCOUNT IS ABOUT TO EXPIRE! UPGRADE NOW!!! AAMkAGZjOTlkOWExLTM2MDEtNGI3MS0.............. Josh Rickard Research 2019-02-28T18:28:36Z 2019-02-28T18:28:36Z Upgrade Your Account! AAMkADAyNTZhNmMyLWNmZTctNDIyZC0.............. Josh Rickard Josh Rickard 2019-01-24T18:41:11Z 2019-01-24T18:41:11Z New or modified user account information AAMkAGZjOTlkOWExLTM2MDEtNGI3MS04.............. Microsoft Online Services Team Research 2019-01-24T18:38:06Z 2019-01-24T18:38:06Z [{'MessageText': 'Succesfull'}]
有关更多示例和用法,请参阅[wiki][wiki]。
开发设置
我提供了一个包含所有依赖项的Dockerfile,它当前正在调用bin\pyews_test.py
。如果你想测试新功能,我建议你使用这个dockerfile而不是virtualenv。您可以调用以下命令来构建一个新容器,但保留依赖项,除非它们在requirements.txt或dockerfile的任何其他更改中发生了更改。
docker build --force-rm -t pyews .
要运行容器,请使用以下命令:
docker run pyews
发布历史记录
- 1.0.0条
- PY EWS向PYPI的初始发布
- 1.0.1条
- 使用新的参考链接更新文档
元
乔希·里卡德–@MSAdministrator–rickardja@live.com
根据麻省理工学院的许可证发行。有关详细信息,请参见LICENSE
。
贡献
- 叉它(https://github.com/swimlane/pyews/fork)
- 创建功能分支(
git checkout -b feature/fooBar
) - 提交更改(
git commit -am 'Add some fooBar'
) - 推到分支(
git push origin feature/fooBar
) - 创建新的拉取请求