I am building an application for sending emails from Gmail to Exchange mailbox using Gmail Rest Api. I have done the following things so far.
- I have successfully created source and destination mailboxes.
- I am able to send messages by calling messages.list and messages.get functions.
- To check for new emails, I have to loop through all messageIds, even those ones which I have already sent to Exchange mailbox.(i.e. message Ids of the older emails)
- I have made sure no duplicates emails are sent to Exchange mailbox.
Since I have to loop through all the messageIds in Gmail mailbox for checking new Emails, I might have a performance issue when the number of emails are large. I want to know if there is an efficient way to get only new emails where I don't have to loop through all the messageIds. One more thing, I am searching in only Inbox label for new email arrivals, is there any other Label I need to search in ? I believe new Emails arrive in Inbox, Important and Spam labels only, is there something else I need to know about it?
Before sending the Google emails to Exchange mailbox, I am putting them in a database table. To solve my problem, I am planning to add a datetime field in the email table to track down the new emails in a particular date and time. I am not sure this idea will work or not so I need an expert advice on this issue.