1
votes

I need to read mails from Mail Server via IMAP and store in DB. My question is

  1. How i can know which mails are already stored in DB and which are now. Based on timestamp? But in that case I have to loop through all the mails and get the timestamp. I dont want to loop through or get all the mails because the mailbox will be huge.

What approach should i take? Should i forward new mails to a temp account - read from that account and then delete that mail?

Please let me know ASAP

Thanks

1

1 Answers

0
votes

The question is do you need to retain those emails on the IMAP server? or can you simply delete them after the download?

All IMAP servers assign a special Unique ID (uid) to each email as it arrives in the mailbox. Uids are assigned in incremental order. In case of most servers those uids are also stable across sessions, and never change.

This means that to know what emails are new you just need to remember the last uid you downloaded previously.

For reading emails you'll need an IMAP library, I recomend this one: http://www.limilabs.com/mail, but please note that I was involved in the development and it is a commercial product.

Here's the article that shows how to get new emails from the server and the details on unique id in IMAP