How to read users outlook email using Oauth2?
Asked Answered
C

1

6

I'm building a service which scans peoples email for specific PDF attachments and indexes them. I implemented this with OAuth2 for Gmail using their extensive Gmail API which works perfectly fine.

I now want to implement the same for outlook/live/hotmail. So I searched around, and I mainly read that you can "Connect to Outlook.com IMAP using OAuth 2.0" (tutorial here). The thing is that this implements a full IMAP connection. As far as I know this is more meant for aftermarket applications with which the user can view and send his email, not for applications which need to download some email in the background (like mine).

I haven't worked with IMAP from within code, but the main problems I see with this now is that:

  1. If I read emails they will be set to "read" in the inbox of the user, which I obviously don't want (I don't want to interfere with the normal email usage of the user).
  2. I will need to either stay connected with all email inboxes, or constantly loop through all email inboxes to get new emails.

My questions are actually;

  1. Is there no other way than IMAP to get users outlook.com email?
  2. Or are my problems actually not problems and should I just create an IMAP "receiver" for all the outlook email accounts?
Camelopardus answered 5/8, 2015 at 11:29 Comment(3)
Point 1 is not a problem. You just need to use body.peek variants of fetch to avoid setting the read flag.Belloc
And as for item 2, you should probably have one connection per account, and use the IMAP IDLE extension, which is by and large ubiquitous.Stirling
Have you gone through this ? msdn.microsoft.com/en-us/library/dn440163.aspxFluttery
B
1

In answer to point #1, according to Max, you can use body.peak to avoid this.

In answer to point #2, according to triplee, you can connect to all of the accounts and then use an IMAP extension called IDLE.

In answer to point #3, I found the Outlook REST API which includes options to read the email and you can call GET https://outlook.office.com/api/beta/me/messages on a regular basis to get all messages in the user's account or you can call GET https://outlook.office.com/api/v1.0/me/messages on a regular basis to get all messages in the user's inbox. You can find a full list of the REST APIs operations here.

In answer to point #4, I believe that some of your problems are problems and others aren't. I believe that you don't have any technical problems. However, I believe that you are correct that IMAP is not designed for applications like yours as is shown in the Wikipedia article on IMAP which reads (bold is mine),

In computing, the Internet Message Access Protocol (IMAP) is an Internet standard protocol used by e-mail clients to retrieve e-mail messages from a mail server over a TCP/IP connection. IMAP is defined by RFC 3501.

Also, in RFC 3501 which defines the original IMAP protocol it refers to email clients which from the absract reads (bold is mine),

The Internet Message Access Protocol, Version 4rev1 (IMAP4rev1) allows a client to access and manipulate electronic mail messages on a server.

Biannulate answered 10/9, 2015 at 10:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.