Receive E-mails from mail server using POP3 and VB .net

Hello,

I was always thinking if i could send and receive e-mails using .Net technology, i was shocked to know that .Net 4 has no POP3 class so one could receive e-mails just like in microsoft Outlook, regardless that Outlook uses POP3, IMAP and SMTP to both send and receive e-mails from e-mail servers.

I was able to finish the send E-mail part successfully, though i've not finished the attachment and the Html parts, but the receiving e-mails part still out there somewhere i did not do it, though i managed to connect to pop3 servers and receive the +OK response successfully.

I'm using an old labtop (WinXpSp3 Home Edition) with VS2010 along with all the .Net kits installed. I've search the internet for pop3-vb.net resources and i could not land on something that works 100% with the receive E-mails part although i ran into some C# codes that helped me to take the first step which is the Response from the server (Gmail.com).

Another thing to tell you, is Gmail.com have 2-Step Verification method that if enabled, it enables you to protect your Google account and provide you with a password to work with applications like this one (The E-mail Client). If you've dealt before with Outlook then you should already know that, you use your Application passworl to login to your Gmail.com account associated with your Google account, here is a link to explain all the 2-Step Verification method, if you don't have a Gmail.com or not working through 2-Step Verification method then, ignore this.

Also you have to know all about incoming and outgoing Ports, Server and of course User Name and PassWord, and remember to always use the full e-mail address (your_username@emailserver.com) not just your username, here is some info about E-mail server settings:

Hotmail Settings

- Incoming Server(pop3.live.com) port(995) Secure Connection (SSL) is a must
- Otgoing Server(smtp.live.com) port(587) Secure Connection (TLS) is a must

Note that Hotmail.com have both free and paid accounts, but both supports E-mail clients. So you should go inside your E-mail settings to enable POP3 and forwarding option to be able to work with E-mail clients.

Yahoo Settings

Incoming Server(pop.mail.yahoo.com) port(995) Secure Connection (SSL) is not a must if you're using the free mail.
Outgoing Server(smtp.mail.yahoo.com) port(465) Secure Connection (TLS) is a must

Note that Yahoo.com have both free and paid accounts, but both supports E-mail clients. So you should go inside your E-mail settings to enable POP3 and forwarding option to be able to work with E-mail clients.

Gmail Settings

Incoming Server(pop.gmail.com) port(995) Secure Connection (SSL) is a must
Outgoing Server(smtp.gmail.com) port(587) Secure Connection (TLS) is a must

Finally, i would really like to suggest using Outlook as a practise first, try to establish a connection with your mail server and send some e-mail and receive some, just to make sure your mail server is sat up correctly.

VB.Net Send E-mail

So easy, huh ?!

VB.Net Receive E-mail

  • Another VB Project.

Of course this is not it, I'm still working on errors i receive .... keep up!


List of Updates

Update (1) Aug,15,2012 - I was able to successfully get response from Gmail (pop.gmail.com) server and pass my Username and password.
Update (2) Aug,17,2012 - Retrieving the number of messages from Inbox into a TextBox control.
Update (3) Aug,17,2012 - Get list of E-mails and download them and read them .
Update (4) Jan,07,2013 - Fixing issues and the final source code download .

Code Project - evry1falls
Code Project article

POP Commands

Command Responses Examples
USER name +OK name is welcome here 
-ERR never heard of name
USER David 
+OK Please enter a password
- Note that this should be sent first ....
PASS string +OK maildrop locked and ready 
-ERR invalid password 
-ERR unable to lock maildrop
PASS test 
+OK valid logon
QUIT +OK +OK Server closing connection
STAT +OK nn mm STAT 
+OK 2 320
- Returns how many E-mails are in Inbox .....
LIST [msg] +OK scan listing follows 
-ERR no such message
LIST 
+OK 2 messages (320 octets) 
1 120 
2 200 
... 

LIST 2 
+OK 2 200
- Get a list of all E-mails you've waiting for .....
RETR msg +OK message follows 
-ERR no such message
RETR 1 
+OK 120 octets 
< the POP3 server sends the entire message here >
- Retrieves E-mail messages from the server .....
DELE msg +OK message deleted 
-ERR no such message
DELE 2 
+OK message deleted
NOOP +OK no transaction NOOP 
+OK
- Stands for (No Operation) : checks the server status ....
LAST +OK nn LAST 
+OK 2
RSET +OK RSET 
+OK maildrop has 2 messages (320 octets)
Additional Commands
TOP msg nn +OK top of msg 
-ERR
TOP 1 10 
+OK 
< first 10 lines of the header >
RPOP user +OK 
-ERR
RPOP david 
+OK enter password

Back


All Rights Reserved to the Developer evry1falls

Free Web Hosting