简体   繁体   中英

Office 365 Email Watcher

I wanted to write a class library to watch over an inbox for new mails with a particular subject and download the attachment. The end goal is to publish the library in Azure as a WebJob / API with the ability to use this library to host it on-premise. We are also planning to integrate this with a workflow functionality that we have already developed. I have found the following stuff online but have some limitations with each.

  1. Logic Apps has a connector but I will have to write something separate for on-premise.
  2. Office Rest APIS has several APIs exposed but all of these has redirect URL for logging user in. I wanted something like a service principal in this case which can call the URL directly without redirection to MS login page.
  3. Other articles uses Interop DLLs which I guess would create problems when hosting as a WebJob as I have seen in the past.

Please help me with the what would be the best approach and if there is a library built in for this which I'm not able to find.

Thanks a lot in advance.

The Microsoft Graph API would be a pretty good place for getting user emails.

Here is the operation you are looking for: https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/user_list_messages

So you will need to make a request to something like:

https://graph.microsoft.com/v1.0/users/user@company.com/messages

And you can do this with a service principal. You will need the Mail.Read app-only permission (Read mail in all mailboxes). This will require you to be an Azure AD admin to consent. You can find details on the permission scopes here: https://graph.microsoft.io/en-us/docs/authorization/permission_scopes .

Oh, and there are SDKs so you don't need to write all the stuff yourself: https://graph.microsoft.io/en-us/code-samples-and-sdks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM