Receive Emails in VB 2010

Day : Aug,12,2012
Send & Receive E-mails from E-mail server using VB .net
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 laptop (WinXpSp3 Home Edition) with VS2010 along with all the .Net kits installed. I've search the internet for 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 (
Another thing to tell you, is have 2-Step Verification method that if enabled, enables you to protect you Google account and provide you with a password to work with applications like this one (E-mail Client). If you dealt with Outlook before you should already knew that; you use your Application password to login to your account associated with your Google account, here is a link that explains all of the 2-Step Verification method, if you don't have a or not working through 2-Step Verification method then you must 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 ( not just your username, here is some info about E-mail server settings:
Hotmail Settings
Incoming Server( port(995) Secure Connection (SSL) is a must
Outgoing Server( port(587) Secure Connection (TLS) is a must
Note that 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( port(995) Secure Connection (SSL) is not a must if you're using the free mail.
Outgoing Server( port(465) Secure Connection (TLS) is a must
Note that 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( port(995) Secure Connection (SSL) is a must
Outgoing Server( 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.

The Send E-mail Part

Imports System.Net.Mail 'The Mail Class we use to send e-mails
Public Class SendFrm 'The form name : SendFrm 
Dim SmtpSvr As New Net.Mail.SmtpClient()
Dim E_mail As New Net.Mail.MailMessage()
Dim UsrNm, Pwd, Srve As String
Dim Int_port As Integer
Private Sub SendFrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
UsrNm = ("") 'I'm using 
Pwd = ("Your_Password") 'My 2-Step Verification Password (Link) coz i enable this method, if not then your regular Password. 
Srve = ("")
Intport = 587
End Sub
Private Sub Label11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label11.Click
'I'm using Label11 to send : Name (Send) 
SmtpSvr.UseDefaultCredentials = False
SmtpSvr.Credentials = New Net.NetworkCredential(UsrNmt.ToString, Pwd.ToString)
SmtpSvr.Port = Intport
SmtpSvr.Host = Srve.ToString
E_mail = New MailMessage()
E_mail.From = New MailAddress(UsrNm.ToString, "Whatever_You_Desire", System.Text.Encoding.UTF8)
E_mail.IsBodyHtml = False 'Still Working on it. 
E_mail.Body = ("Hello, This is my first E-mail though My Client")
SmtpSvr.EnableSsl = True
E_mail.To.Add(TxtFrnd.Text.ToString) 'TextBox Name : TxtFrnd 
E_mail.Subject = (TxtSub.Text.ToString) 'TextBox Name : TxtSubCursor = Cursors.WaitCursor
MsgBox("mail sent")
Cursor = Cursors.Default
End Sub
So easy, huh ?!
The Receive E-mail Part
This is another VB Project.
Imports System.IO
Imports System.Net.Sockets
Imports System.Text
Imports System.Net.Security
Class Form1
Dim Read_Stream As StreamReader
Dim POP3 As New TcpClient
Dim PopHost As String = ""
Dim UserName As String = ""
Dim Password As String = "My2stepVerficationPass"
Dim Server_Response As String
Dim response As StreamWriter

Private Sub CmdDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdDownload.Click

Cursor = Cursors.WaitCursor
POP3.Connect(PopHost, 995)
TextBox1.AppendText(Cons("STAT ")) 'TextBox Name : TextBox1 to receive response from server using (STAT) command,
'Note : In the bottom there is a table with all POP commands and responses.I'm using Cons Function to send commands to POP server.
Cursor = Cursors.Default
End Sub

Function Cons(ByVal server_Command As String)
Dim m_buffer() As Byte = System.Text.Encoding.ASCII.GetBytes(server_Command)
Dim m_sslStream = New SslStream(POP3.GetStream(), False)
Dim bytes As Int64 = m_sslStream.Read(m_buffer, 0, m_buffer.Length)
Return (Encoding.ASCII.GetString(m_buffer, 0, bytes))
End Function

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

Update (1) Aug,15,2012 - I was able to successfully get response from Gmail ( server and pass my Username and password.
POP Commands
USER name+OK name is welcome here
-ERR never heard of name
USER David
+OK Please enter a password
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
+OK 2 320
LIST [msg]+OK scan listing follows
-ERR no such message
+OK 2 messages (320 octets)
1 120
2 200


+OK 2 200
RETR msg+OK message follows
-ERR no such message
+OK 120 octets
< the POP3 server sends the entire message here >
DELE msg+OK message deleted
-ERR no such message
+OK message deleted
NOOP+OK no transactionNOOP
+OK 2
+OK maildrop has 2 messages (320 octets)
Additional Commands
TOP msg nn+OK top of msg
TOP 1 10
< first 10 lines of the header >
RPOP user+OK
RPOP david
+OK enter password

Update (1) Aug,15,2012 - I was able to successfully get response from Gmail ( server and pass my Username and password.
Update (2) Aug,17,2012 - Retrieving the number of E-mails from POP3 Mail Server .
Update (3) Aug,18,2012 - Get list of E-mails and download them and read them to your application.

Here are some online Visual Basic lessons and courses :

OOP Toturial Index Polymorphism VB 2010 VB 2010 Optimization object oriented programming OOP Crystal Report Freelance Optimization VB 2010 MS-Access 2003/2007 ADO.Net visual basic course Crystal report and VB .net Earn money programming - Programmer Jobs Online Online courses VB2010 Receive E-mail Search Optimization Sql Server Visual Basic Visual Basic 2010 online courses Visual Basic Job online visual basic courses pop server pop3 visual basic courses online visual basic online courses ADO.Net online mode Insert Date into SqlServer using VB.Net Install Crystal report No error message available SqlServer VB 2010 DataGridView Visual Basic .Net and SQL Server Date-Time Visual Basic .net Visual Basic Class connecting to access database via dao using database e-mail .net framework 4.5.2 Activate Visual Studio 2005 Advantage Data Dictionary Advantage Database Visual Basic 2010 Binary Diff Buttons sound in VB 2010 CR for VS2015 CRforVS2015 Check internet connection Command Prompt Communicate with a client Compare two applications Compare two strings and return differences Compare two treeviews Conversion from type 'DBNull' to type 'String' is not valid Crystal Report with Protected MS-Access database DAO + VB .NET + ACCESS DataGridView VB 2010 Programming DataGridView with MS-Access DataReader DevExpress 12.2.9 Serial crack full DevExpress VB.Net DevExpress full Download DevExpress 12 Dxperience 12.2.4 Dxperience full serial crack Event Planning Example on connecting to Advantage Data Dictionary from VB.Net FC Command Fade Image VB 2010 MS Access 2010 MS SQL SERVER 2000 INSTALLATION MS VB.Net MS-Access 2007 2010 MS-Access Compact and Repair from VB 2010 Programmatically Make sure application is running Microsoft Visual Basic .Net Math Functions list OOP Lesson 11 OOP Lesson 12 OOP Lesson 6 OOP Lesson 7 OOP Lesson 8 OOP Lesson 9 OOP Lesson13 OOPTutorials POP3 Commands in VB 2010 Point of sale application Purchase Receive E-mail from Gmail in VB 2010 Requirement Doc Reverse Strings SQL Server 2000 SQL Server 2000 date-time type Sales and Stores application Source code download Sql Server and VB.Net The Microsoft.ACE.OLEDB.12.0 provider is not registered on the local machine The following control could not be licensed There is already an open DataReader associated with this Command which must be closed first Toolbox items Topmost - Inputbox Sloved Tx TxtControl for Visual Basic Use case definition VB 2005 Activation Code VB 2010 Compare and return differences VB 2010 Create Controls at Run-Time with events VB 2010 How to fade Image VB 2010 Internet VB 2010 Read Text Files VB 2010 Reverse Strings VB 2010 check for internet connection VB 2010 database compact and repair VB 2010 progressbar VB.Net Math functions VB.Net Search Optimization SqlServer 2000 lessons VB2010 VS 2051 VS2010 VS2015 VS2017 VS2019 Virus W32.Sality Visual Basic Application Development Visual Basic Virus Visual Studio Serial Number book classes vb compare windows applications and return the difference. crystalDecision older version download crystal report for VB 2010 dtSearch dtSearch Engine dtSearch Engine download full free free make sure application is installed object oriented programming languages oop Lesson 10 play sounds in Visual progress bar result code: DB_SEC_E_AUTH_FAILED(0x80040E4D). sqlserver2000 project (new-save-edit-delete) the application failed to initialize properly 0xc000007b tutorials vb .Net functions list. vb 2010 Create TextBox with events at Project Runtime vb 2010 receive Emails visual basic .Net FlexGrid visual basic courses win10 32 bit solution برنامج المشتريات و المبيعات و المخازن
Show more