Download emails from Gmail via POP3
Accessing Gmail with POP3 is a bit different that accessing other POP3 servers. Still is quite easy with Mail.dll POP3 client. Remember that POP3 protocol unlike IMAP does not store the unseen information on the server.
Mail.dll has of course IMAP support
First remember to enable POP3 in Gmail.
You can read more about Gmail’s POP3 behavior.
Remember that Gmail only allows secure SSL connections, so we need to use ConnectSSL method.
// C# code: using(Pop3 pop3 = new Pop3()) { pop3.ConnectSSL("pop.gmail.com"); pop3.Login("your_email@gmail.com", "password"); foreach (string uid in pop3.GetAll()) { var eml = pop3.GetMessageByUID(uid); IMail mail= new MailBuilder() .CreateFromEml(eml); Console.WriteLine(mail.Subject); Console.WriteLine(mail.Text); } pop3.Close(); }
' VB.NET code: Using pop3 As New Pop3() pop3.ConnectSSL("pop.gmail.com") pop3.Login("your_email@gmail.com", "password") For Each uid As String In pop3.GetAll() Dim email As IMail = New MailBuilder() _ .CreateFromEml(pop3.GetMessageByUID(uid)) Console.WriteLine(email.Subject) Console.WriteLine(mail.Text) Next pop3.Close() End Using
If you want to have a greater control over your emails you should use IMAP protocol.
With IMAP you can:
- access emails in different folders
- copy or move messages between folders
- mark messages read/unread
- flag messages
- download emails’ basic information very fast
- use push email
Check POP3 vs IMAP for details.
Mail.dll contains ready to use IMAP client. Take a look on how to download email from Gmail using IMAP sample.
If you like the idea of simple Gmail access just give it a try for yourself and download it at: Mail.dll .NET email component.
November 15th, 2014 at 13:26
[…] articles can help you with that: How to enable POP3 for Gmail How to enable IMAP for Gmail How to enable IMAP for […]