用于与内部部署和Office 365 Exchange Web服务交互的Python包

py-ews的Python项目详细描述


py ews

Documentation Status

.______   ____    ____       ___________    __    ____   _______.
|   _  \  \   \  /   /      |   ____\   \  /  \  /   /  /       |
|  |_)  |  \   \/   / ______|  |__   \   \/    \/   /  |   (----`
|   ___/    \_    _/ |______|   __|   \            /    \   \    
|  |          |  |          |  |____   \    /\    / .----)   |   
| _|          |__|          |_______|   \__/  \__/  |_______/    

与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。此示例将演示如何使用GetSearchableMailboxesEWS终结点来标识您有权访问的邮箱。

一旦确定了邮箱引用ID列表,就可以使用SearchMailboxesEWS端点开始搜索所有这些邮箱。

然后,将使用DeleteItemEWS终结点从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条
    • 使用新的参考链接更新文档

乔希·里卡德–@MSAdministratorrickardja@live.com

根据麻省理工学院的许可证发行。有关详细信息,请参见LICENSE

贡献

  1. 叉它(https://github.com/swimlane/pyews/fork
  2. 创建功能分支(git checkout -b feature/fooBar
  3. 提交更改(git commit -am 'Add some fooBar'
  4. 推到分支(git push origin feature/fooBar
  5. 创建新的拉取请求

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何下载多个。java中的PDF文件   linux Java打开文件,形成实际用户主页~/   java如何在时间线内维护TableView选择?   java Hibernate注释@Where vs@WhereJoinTable   Java读/写访问异常FileNotFoundException(访问被拒绝)   继承在Java中是否可以扩展最后一个类?   Android HttpClient使用java使应用程序崩溃。lang.OutOfMemoryError:pthread_create   java为什么即使我在proguardproject中添加了jar文件,也会出现这种错误。txt?   如果添加JButton,swing Java FocusListener和KeyListener将无法工作   java使用solrj检索json格式的SolrDocument   使用Microsoft Visual Studio代码进行Java编程   java NoClassDefFoundError:org/apache/log4j/Logger   哈希集中包含相等对象的java   java中的参数化构造函数是否需要有一个主体?   java类似于NetBeans不必要的代码检测器   Java实践问题   java Blackberry“[projectname].调试文件丢失”和“I/O错误:找不到程序”jar