Hi, I need to do the following: 1. initially download all my emails from gmail (all folders, all flags) 2. save into a sql server table 3. on a regular basis, download new emails which do not already exist in my sql server table (all folders, all flags)
Pls assist me with code sample.
Thank you
I can recommend using IMAP.
If you are targeting Gmail only, use its 'All Mail' folder (use CommonFolders class).
Download most common email information, including Gmail flags first. You can use GetMessageInfoByUID for that:
https://www.limilabs.com/blog/get-email-information-from-imap-fast
This way you can find which uids are already in your SQL database and mark those that aren't to be downloaded. Also you don't need to traverse entire folder structure (folders are in fact labels in Gmail and all messages are in stored in 'All Mail' folder).
Then use GetMessageByUID to download actual messages (this includes attachments).
Articles you may find useful: https://www.limilabs.com/blog/get-new-emails-using-imap
https://www.limilabs.com/blog/download-unseen-emails-from-gmail-using-imap-video
https://www.limilabs.com/blog/unique-id-in-imap-protocol