





Introduction
EAGetMail is a POP3 & IMAP4 component which supports all operations of POP3/IMAP4/MIME protocol. This tutorial covers everything of retrieving email and parsing email with EAGetMail in Visual Basic 6.0.
Before you can use the following sample codes, you should download the EAGetMail Installer and install it on your machine at first.
To better demonstrate how to use EAGetMail retrieving and parsing email, let's create a Visual Basic 6.0 Standard EXE project at first, then add a CommandButton on the Form, double-click this button. It is like this:
To use EAGetMail POP3 & IMAP4 ActiveX Object in your project, the first step is "Add reference of EAGetMail to your project". Please choose menu->"Project" -> "References"- > and choose the "EAGetMailObj ActiveX Object", click "OK", the reference of EAGetMail ActiveX Object will be added to your project, and you can start to use EAGetMail to retrieve and parse email in your project.
Now add the following codes to the project. The following code demonstrates how to retrieve email from a POP3 mail account. This sample downloads emails from POP3 server and deletes the email after the email is retrieved.
Option Explicit
Const MailServerPop3 = 0
Const MailServerImap4 = 1
Private Sub Command1_Click()
Dim curpath As String
Dim mailbox As String
Dim oTools As New EAGetMailObjLib.Tools
' Create a folder named "inbox" under current directory
' to save the email retrieved.
curpath = App.Path
mailbox = curpath & "\inbox"
oTools.CreateFolder mailbox
Dim oServer As New EAGetMailObjLib.MailServer
oServer.Server = "pop3.emailarchitect.net"
oServer.User = "test@emailarchitect.net"
oServer.Password = "testpassword"
oServer.Protocol = MailServerPop3
' If your POP3 requires SSL connection
' Please add the following codes
' oServer.SSLConnection = True
' oServer.Port = 995
On Error GoTo ErrorHandle:
Dim oClient As New EAGetMailObjLib.MailClient
oClient.LicenseCode = "TryIt"
oClient.Connect oServer
MsgBox "Connected"
Dim infos
infos = oClient.GetMailInfos()
MsgBox UBound(infos) + 1 & " emails"
Dim i As Integer
For i = LBound(infos) To UBound(infos)
Dim info As EAGetMailObjLib.MailInfo
Set info = infos(i)
MsgBox "Index: " & info.Index & "; Size: " & info.Size & _
"; UIDL: " & info.UIDL
' Receive email from POP3 server
Dim oMail As EAGetMailObjLib.Mail
Set oMail = oClient.GetMail(info)
MsgBox "From: " & oMail.From.Address & _
vbCrLf & "Subject: " & oMail.Subject
Dim fileName As String
' Generate a random file name by current local datetime,
' You can use your method to generate the filename if you do not like it
fileName = mailbox & "\" & oTools.GenFileName(i) & ".eml"
' Save email to local disk
oMail.SaveAs fileName, True
' Mark email as deleted from POP3 server.
oClient.Delete info
Next
' Quit and pure emails marked as deleted from POP3 server.
oClient.Quit
Exit Sub
ErrorHandle:
MsgBox Err.Description
End Sub
If you set everything right, you can get emails in the mail folder. If the codes threw exception, then please have a look at the following section.
Where can I get my POP3 server address, user and password?
Because each email account provider has different server address, so you should query your POP3 server address from your email account provider. User name is your email address or your email address without domain part. It depends on your email provider setting.
When you execute above example code, if you get error about "Networking connection" or "No such host", it is likely that your POP3 server address is not correct. If you get an error like "Invalid user or password", it is likely that you did not set the correct user or password.
Finally, if you have already set your account in your email client such as Outlook or Window Mail, you can query your POP3 server address, user in your email client. For example, you can choose menu -> "Tools" - > - "Accounts" - > "Your email account" - > "Properties" - > "Servers" in Outlook express or Windows Mail to get your POP3 server, user. Using EAGetMail to receive email does not require you have email client installed on your machine or MAPI, however you can query your exist email accounts in your email client.
In this section, I introduced the basic things of retrieving email in VB 6.0 with EAGetMail. At next section I will introduce how to retrieve email from IMAP4 server.
Next: Retrieve email from IMAP4 server in VB 6.0 ->Comments
If you have any comments or questions about above example codes, please click here to add your comments.
Send Email - C# - VB6 - Visual Basic - VC++ - Managed C++ - Delphi
Retrieve Email and Parse Email - C# - VB6 - Visual Basic - VC++ - Managed C++ - Delphi
Email Solution - Email Server - DomainKeys/DKIM - Disclaimer
2003 - 2011 © Copyright AdminSystem Software Limited. All rights reserved.
About us