Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone help me in downloading emails from my gmail account in C# windows application.
Thanks to all for your valuable help.


I need one more help. When i try to download each time, all mails are getting downloaded. How can i restrict to download the mails which I haven't downloaded yet?
Posted
Updated 20-Mar-15 21:28pm
v2
Comments
Joan Magnet 20-Mar-15 6:28am    
Are you working on a pop client?

You can use google REST API too.

https://developers.google.com/gmail/api/
Afzaal Ahmad Zeeshan 20-Mar-15 6:56am    
That would not be as much strong as the IMAP protocol itself it. And is still a new technology thus not as much strong and efficient as a trusted protocol (IMAP) is. Please see my solution.
Member 11539268 21-Mar-15 3:24am    
Thanks alot...

Just as to send the emails to the server for delivery a protocol is used (SMTP; Simple mail transfer protocol[^]), in a same manner, to download the emails from the server you require a similar protocol; IMAP; Internet message access protocol[^].

There are none built-in functions in .NET framework or Windows forms applications to let you directly send commands to a server using IMAP protocol. So, either that you need to be using a third-party plugin; which I have also used and I think you would love that library, ImapX[^]. Otherwise, you can use the TCP/IP streams and send requests directly to the server and work with the response (Not a good idea; use the library).

As already mentioned in the comments, you can also use the REST API of Gmail[^] (which will work with Gmail only; off-gmail servers won't work) to fetch messages, threads and drafts etc in a JSON format. But it won't be as much strong and powerful as much that ImapX library is, because ImapX supports IDLE events; letting you download the messages as they are recieved; like a push-notifications.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 20-Mar-15 8:46am    
Gmail should also support POP3 at pop.gmail.com. Doesn't it also worth mentioning?
Generally, the inquirer may need more information, so I added more detail in Solution 1, please see.
—SA
Member 11539268 21-Mar-15 3:24am    
Thanks alot...
[no name] 22-Mar-15 0:08am    
+5, -1 for missing POP, +1 for mentioning IDLE ;-)
- Sebastian
Afzaal Ahmad Zeeshan 22-Mar-15 4:56am    
Thanks for your vote, Sebastian. :)
In addition to Solution 1:

You can find the detail of Gmail settings for IMAP and POP3 here: https://support.google.com/mail/troubleshooter/1668960[^].

If you want to use POP3, I would recommend OpenPOP.NET:
http://openpop.net[^],
http://sourceforge.net/projects/hpop[^].
Not only it implements POP3 protocol. Its main role is to parse mail messages. I wasn't quite satisfied with the quality of this code, so I used it only as a reference, which was invaluable, as it thoroughly takes into account and document the use of those standards. There are well too many standard documents involved in e-mail, especially in MIME types.

So, it's good to use OpenPOP.NET even if you use IMAP.

If you want to use IMAP, it would be useful to look at the simple client sample: https://code.msdn.microsoft.com/windowsdesktop/Simple-IMAP-CLIENT-b249d2e6[^].
You can obtain a set of mail components, including IMAP, POP3 and a lot more, from Microsoft: https://visualstudiogallery.msdn.microsoft.com/28b96cd4-b755-48a0-b686-9abb7d5607a8[^].

This CodeProject article can also be useful: IMAP and POP3 Clients in C#[^].

—SA
 
Share this answer
 
Comments
Member 11539268 21-Mar-15 3:24am    
Thanks alot...
Sergey Alexandrovich Kryukov 21-Mar-15 5:54am    
You are very welcome.
Good luck, call again.
—SA
[no name] 22-Mar-15 0:08am    
5ed
- Sebastian
Sergey Alexandrovich Kryukov 22-Mar-15 11:32am    
Thank you, Sebastian.
—SA
http://rfinochi.github.io/pop3dotnet/

You can use libraries present in the Pop3dotnet.They have several features which includes a function for downloading your e-mails.

If you are a Nuget lover you can always find this dll listed there.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900