Search code examples
c#gmailgmail-imapgmail-pop

How to programatically get ALL (read and unread) messages from gmail, read status, etc?


I have a customer service web app requirement, which requires that I work pull & integrate data from Gmail, eBay, Amazon, and Paypal. My solution is going to be developed in ASP.Net 4 with C#.

The issue that I'm running into is that my client needs pretty much all of the information that Gmail has about each and every email that comes in & the ATOM feed coming from Gmail seems to be a bit lacking. I realize I can also use POP3 or IMAP, but they too are lacking for a number of reasons.

Specifically, the client needs the read status of emails (whether or not THEY have read emails that were sent to THEM). They also need for all of the filters to remain intact. So if an email is tagged with x,y, & z, then I need to know about it.

The ATOM feed only shows me unread emails, so that's out. POP3 has no clue (and rightfully so) whether or not they've read an email or not (unless I pull it into a database and manage read status, myself...but that doesn't work if they actually read a mail from within gmail itself).

IMAP seems like it would give me everything I need, but I'm not 100% sure on that. What do you all think? Also, IMAP is SOOO slow. Is anyone aware of any decent libraries that are fairly fast. We're talking about a customer inbox with some 360,000'ish messages at the present time, & the client would prefer to keep those messages at gmail & not work with a disconnected database.

Thoughts / Opinions?


Solution

  • IMAP does provide read/not-read status for each message and you can pull from particular 'labels' (folders) or just pull from the 'all messages' bucket. You don't need to pull the entire message either, you can ask for headers only, giving you the ability to quickly scan many emails.

    I've been working on a program to pull my entire gmail dataset down for my own tinkering and processing. I'm using linux, and while there are a multitude of imap 'mirror' and imap 'processing' applications out there, I just want to play with the data, being able to do what I want with it, without stuffing it back into an imap server locally. It's been working decently and I'm using the email's UID (modified slightly) as a file name to dump the headers & email data. Of course, you could massage the data and update a database or whatever at that point, I'm just stashing it for post-processing later. Looking for trends in my email, mostly tinkering.

    I tried using the etpan libraries for IMAP processing, didn't find them to my liking, so I've been pulling imap routines from other email programs and servers to play with. I have the RFC's, but really really trying to not reinvent the wheel here if I can help it.

    Yup, not the best answer, but hopefully some information to help. I imagine there are nice libraries for PHP, or other web-based systems, I've been working with C++/C myself.