使用Microsoft Graph API搜索、删除和移动电子邮件的Python包
graphish的Python项目详细描述
graphish
使用Microsoft Graph API从Office 365邮箱中搜索和删除邮件的Python包
当前功能
* Searching
* Create new Search
* Update a Search
* Get Search Folder
* Get Search messages
* Delete Search
* Deleting
* Delete a Message
* Mailbox Rules
* List Mailbox Rules
* Users
* Return a list of email addresses in your Azure AD Tenant
* MailFolder
* Create MailFolder
* Move message to a MailFolder
* List messages in a MailFolder
安装
若要使用,请在本地安装软件包:
安装
本地:
OS X和Linux: 窗口: 若要使用,您需要在azure ad中创建一个新应用程序。请按照以下说明获取相应的机密: https://docs.microsoft.com/en-us/graph/auth-register-app-v2 也请查看这篇关于 此外,如果您希望 获得此信息后,您可以执行以下操作: 要使用 以下是生成graphconnector对象的不同方法,取决于您为应用程序选择的身份验证工作流方法。 若要将 通过使用委派的身份验证(单页、Web应用程序、移动和本机应用程序-授予身份验证流),您可以通过不传递 要将 通过使用应用程序身份验证(客户端凭据授予身份验证流),您可以搜索特定邮箱或所有邮箱。 一旦确定了适当的身份验证并创建了 创建(或实例化)一个 注意:如果使用应用程序身份验证工作流,则可以传入一个或一个userprincipalname列表。如果不传入userprincipalname,则搜索将尝试搜索azure ad租户中的所有邮箱! 您可以使用搜索对象的同一实例并使用 如果您需要邮箱中的邮件文件夹列表,可以使用 如果您需要搜索范围内所有用户的列表: 如果您已经执行了搜索并希望将邮件移动到邮件文件夹,可以执行以下操作: 您还可以使用 如果要更改执行的搜索,可以更新搜索文件夹和各个条件,如搜索文件夹的名称、源文件夹(要搜索的根目录)或筛选器查询本身: 您还可以使用 此外,您还可以列出任何邮箱规则: 您可以在这里找到其他示例
乔什·里卡德–@msadministrator–rickardja@live.com 根据麻省理工学院的许可证发行。有关详细信息,请参见许可证。bash git clone git@github.com:swimlane/graphish.git cd graphish pip install setup.py
pip install graphish
pip install graphish
用法
Graphish的博客文章
https://swimlane.com/blog/swimlane open-sources graphish/
graphish
搜索您的azure租户中的所有用户,则需要在注册期间为您的azure广告应用程序提供user.read.all
权限。图形连接器
graphish
必须首先创建包含所有身份验证信息的graphconnector
对象。一旦您创建了此连接器对象,则用户将此对象作为必需参数提供给此包中的其他类。委派的身份验证
graphish
与委派权限和用户名和密码一起使用,您需要提供clientid、clientsecret、tenantid以及您的帐户用户名和密码。userprincipalname
来搜索自己的邮箱,或者如果要搜索另一个邮箱,请提供userprincipalname
(电子邮件地址):使用(单页、Web应用程序、移动和本机应用程序)身份验证流为您的帐户创建连接器:
fromgraphishimportGraphConnectorconnector=GraphConnector(clientId='14b8e5asd-c5a2-4ee7-af26-53461f121eed',# you applications clientIdclientSecret='OdhG1hXb*UB/ho]A?0ZCci13KMflsHDy',# your applications clientSecrettenantId='c1141d00-072f-1eb9-2526-12802571dd41',# your applications Azure Tenant IDuserPrincipalName='first.last@myorg.onmicrosoft.com',# the user's mailbox you want to searchpassword='somepassword'# password of your normal or admin account)
使用(单页、Web应用程序、移动和本机应用程序)身份验证流为其他用户邮箱创建连接器:
fromgraphishimportGraphConnector# For legacy app grant flow provide a username and passwordconnector=GraphConnector(clientId='14b8e5asd-c5a2-4ee7-af26-53461f121eed',# you applications clientIdclientSecret='OdhG1hXb*UB/ho]A?0ZCci13KMflsHDy',# your applications clientSecrettenantId='c1141d00-072f-1eb9-2526-12802571dd41',# your applications Azure Tenant IDuserPrincipalName='first.last@myorg.onmicrosoft.com',# the user's mailbox you want to searchpassword='somepassword'# password of your normal or admin account)
应用程序验证
graphish
用于应用程序权限,您需要提供clientid、clientsecret和tenantid。使用服务/后台程序身份验证流为您的帐户创建连接器:
fromgraphishimportGraphConnector# For backend / client_credential auth flow just supply the followingconnector=GraphConnector(clientId='14b8e5asd-c5a2-4ee7-af26-53461f121eed',# you applications clientIdclientSecret='OdhG1hXb*UB/ho]A?0ZCci13KMflsHDy',# your applications clientSecrettenantId='c1141d00-072f-1eb9-2526-12802571dd41',# your applications Azure Tenant ID)
使用服务/后台程序身份验证流为其他用户邮箱创建连接器:
fromgraphishimportGraphConnector# For backend / client_credential auth flow just supply the followingconnector=GraphConnector(clientId='14b8e5asd-c5a2-4ee7-af26-53461f121eed',# you applications clientIdclientSecret='OdhG1hXb*UB/ho]A?0ZCci13KMflsHDy',# your applications clientSecrettenantId='c1141d00-072f-1eb9-2526-12802571dd41'# your applications Azure Tenant ID)
创建新搜索
graphconnector
对象,则可以创建新的search
对象。拥有搜索对象之后,就可以创建新搜索、从搜索中检索邮件、获取搜索文件夹、更新搜索文件夹或删除搜索。当您创建新的搜索时,这将在用户邮箱中创建一个隐藏的文件夹(用户无法看到),它将基于您的搜索筛选器query进行填充。
search
对象时,可以指定搜索的范围。有三个与指定搜索相关的用例:search
类的user principal name
参数提供用户主体名称
userprincipalname
参数提供"me"e使用用户名和密码验证工作流时搜索
类search
类上的userprincipalname
参数提供值。这将通过listusers端点拉入你的azure广告中的所有用户。fromgraphishimportSearchsearch=Search(connector)new_search=search.create(searchFolderName='Phishing Search',sourceFolder='inbox',filterQuery="contains(subject, 'EXPIRES')")
从搜索中获取消息
消息
方法来检索在搜索过程中标识的消息:# get all the messages in your search folderformessageinsearch.messages():print(message)# Returns all attributes from a messageprint(message['id'])# returns the message IDprint(message['headers'])# Returns the RFC822 headers of the message
获取邮件文件夹列表
文件夹
方法检索它们:
0
* Searching
* Create new Search
* Update a Search
* Get Search Folder
* Get Search messages
* Delete Search
* Deleting
* Delete a Message
* Mailbox Rules
* List Mailbox Rules
* Users
* Return a list of email addresses in your Azure AD Tenant
* MailFolder
* Create MailFolder
* Move message to a MailFolder
* List messages in a MailFolder
获取用户列表
1
* Searching
* Create new Search
* Update a Search
* Get Search Folder
* Get Search messages
* Delete Search
* Deleting
* Delete a Message
* Mailbox Rules
* List Mailbox Rules
* Users
* Return a list of email addresses in your Azure AD Tenant
* MailFolder
* Create MailFolder
* Move message to a MailFolder
* List messages in a MailFolder
将邮件移动到文件夹
2
* Searching
* Create new Search
* Update a Search
* Get Search Folder
* Get Search messages
* Delete Search
* Deleting
* Delete a Message
* Mailbox Rules
* List Mailbox Rules
* Users
* Return a list of email addresses in your Azure AD Tenant
* MailFolder
* Create MailFolder
* Move message to a MailFolder
* List messages in a MailFolder
创建新的邮件夹
mailfolder
类创建新的mailfolder
3
* Searching
* Create new Search
* Update a Search
* Get Search Folder
* Get Search messages
* Delete Search
* Deleting
* Delete a Message
* Mailbox Rules
* List Mailbox Rules
* Users
* Return a list of email addresses in your Azure AD Tenant
* MailFolder
* Create MailFolder
* Move message to a MailFolder
* List messages in a MailFolder
更新搜索
4
* Searching
* Create new Search
* Update a Search
* Get Search Folder
* Get Search messages
* Delete Search
* Deleting
* Delete a Message
* Mailbox Rules
* List Mailbox Rules
* Users
* Return a list of email addresses in your Azure AD Tenant
* MailFolder
* Create MailFolder
* Move message to a MailFolder
* List messages in a MailFolder
删除搜索
delete
方法删除执行的搜索:
5
* Searching
* Create new Search
* Update a Search
* Get Search Folder
* Get Search messages
* Delete Search
* Deleting
* Delete a Message
* Mailbox Rules
* List Mailbox Rules
* Users
* Return a list of email addresses in your Azure AD Tenant
* MailFolder
* Create MailFolder
* Move message to a MailFolder
* List messages in a MailFolder
列出邮箱规则
6
* Searching
* Create new Search
* Update a Search
* Get Search Folder
* Get Search messages
* Delete Search
* Deleting
* Delete a Message
* Mailbox Rules
* List Mailbox Rules
* Users
* Return a list of email addresses in your Azure AD Tenant
* MailFolder
* Create MailFolder
* Move message to a MailFolder
* List messages in a MailFolder
其他示例
发布历史记录
元
贡献
git checkout-b feature/foobar
)git commit-am'add some foobar'
)git push origin feature/foobar
)推荐PyPI第三方库