In previous section, I introduced how to use UIDL function to mark the email has been downloaded. In this section, I will introduce how to download email with background service in VB 6.0.
Sections:
In an ASP/ASP.NET email application, if email download takes longer than the timeout value (in seconds) that the current asp page is allowed to run, user will get an error “ASP Timeout”. This often happens when user has a large quantity of emails to download or user downloads emails via a slow connection. By default the timeout is set to 90 seconds, it is easy to exceed this limit.
Obviously, a solution to ASP timeout is to set ASPScriptTimeout a larger value. You may click here for details. Technically the timeout problem can be solved in this way; however, some users may get frustrated and press the stop button on the browser toolbar as he waits too long.
EAGetMail POP3 Component introduces a more intelligent method to retrieve emails in background. You should download the EAGetMail Service installer and install it on your machine at first. Then you can use MailClient.GetMailsByQueue method to send the request to EAGetMail Service, the method returns to the user immediately and the EAGetMail Service performs task in background.
Important
To run the following example, you need to download EAGetMail and EAGetMail Service at first, and then install both on your machine.
Note
Remarks: All of examples in this section are based on first section: A simple VB 6.0 project. To compile and run the following example codes successfully, please click here to learn how to create the test project and add reference to your project.
The following example codes demonstrate how to use EAGetMail POP3 component to retrieve
email with background service. In order to run it correctly, please change
email server
, user
, password
, folder
, file name
values.
Note
To get the full sample projects, please refer to Samples section.
Option Explicit
Const MailServerPop3 = 0
Const MailServerImap4 = 1
Const MailServerEWS = 2
Const MailServerDAV = 3
Const MailServerMsGraph = 4
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
' Enable SSL/TLS connection, most modern email servers require SSL/TLS by default
oServer.SSLConnection = True
oServer.Port = 995
' If your POP3 doesn't deploy SSL connection
' Please use
' oServer.SSLConnection = False
' oServer.Port = 110
On Error GoTo ErrorHandle:
Dim oClient As New EAGetMailObjLib.MailClient
oClient.LicenseCode = "TryIt"
' Leave a copy of message on server.
Dim leaveCopy As Boolean
leaveCopy = True
' Download emails to this local folder
Dim downloadFolder As String
downloadFolder = mailbox
' Send request to EAGetMail Service, then EAGetMail Service retrieves email
' in background and this method returns immediately.
oClient.GetMailsByQueue oServer, downloadFolder, leaveCopy
Exit Sub
ErrorHandle:
MsgBox Err.Description
End Sub
EAGetMail Service provides another advanced feature which allow you set a POP3/IMAP4 account in the EAGetMail Service Manager. EAGetMail Service can download emails from this account in specified time interval. If you need to process the email in the mailbox on a regular basis, you just need to create your mail process application, you don’t need to write your email download task part.
Finally you just need to set your mail account in EAGetMail Service Manager and specify your application or COMMAND, EAGetMail service will download the emails and invoke your application automatically. Please refer to Mail Pull for more detail.
I also suggest that you have a look at Parse Non-Delivery Report (NDR) using EAGetMail Service. It demonstrates how to set a schedule to check a mailbox and insert non-delivery report to SQL database.
Next Section
At next section I will introduce how to parse email in VB 6.0.
Appendix
Comments
If you have any comments or questions about above example codes, please click here to add your comments.