Work with EAGetMail Service


EAGetMail Service is an advanced service which can download emails from POP3/IMAP4 servers in background. It provides many features such as retrieving and saving emails to specified folders in schedule, and starting a specified application to handle downloaded emails.

This service facilitates EAGetMail POP3/IMAP4 Component developers that their applications can now accept an email retrieving request from EAGetMail Application, and then download emails in background. This is particularly useful for ASP/ASP.NET web application.

Retrieve emails in background

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 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.

Example

[Visual Basic 6.0]
Public Sub ReceiveMail( _
ByVal sServer As String, _
ByVal sUserName As String, _
ByVal sPassword As String, _
ByVal bSSLConnection As Boolean)
    
    Const MailServerPop3 = 0
    Const MailServerImap4 = 1
 
    'For evaluation usage, please use "TryIt" as the license code, otherwise
        the '"invalid license code" exception will be thrown. However, the object will expire
        in 1-2 months, then '"trial version expired" exception will be thrown.
    Dim oClient As New EAGetMailObjLib.MailClient
    oClient.LicenseCode = "TryIt"
    
    'To receive email from imap4 server, please change 'MailServerPop3
        to MailServerImap4 in MailServer constructor
    Dim oServer As New EAGetMailObjLib.MailServer
    oServer.Server = sServer
    oServer.User = sUserName
    oServer.Password = sPassword
    oServer.SSLConnection = bSSLConnection
    oServer.Protocol = MailServerPop3
    
    ''by default, the pop3 port is 110, imap4 port is 143, 'the pop3
        ssl port is 995, imap4 ssl port is 993 'you can also change the port like this 'oServer.Port
        = 110
    If oServer.Protocol = MailServerImap4 Then
        If oServer.SSLConnection Then
            oServer.Port = 993 'SSL IMAP4
        Else
            oServer.Port = 143 'IMAP4 normal
        End If
    Else
        If oServer.SSLConnection Then
            oServer.Port = 995 'SSL POP3
        Else
            oServer.Port = 110 'POP3 normal
        End If
    End If
    
    On Error GoTo ErrorHandle
        Dim leaveCopy As Boolean
        leaveCopy =  True 'leave a copy of message on server.
        Dim downloadFolder As String
        downloadFolder = "c:\popdownload" 'download emails to this local
            folder. '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:
        ''Error handle
        MsgBox Err.Description
End Sub
 
[VBScript]
Sub ReceiveMail( _
ByVal sServer, _
ByVal sUserName, _
ByVal sPassword, _
ByVal bSSLConnection)
    
    Const MailServerPop3 = 0
    Const MailServerImap4 = 1
 
    'For evaluation usage, please use "TryIt" as the license code, otherwise the
    '"invalid license code" exception will be thrown. However, the object will expire in 1-2 months, then
    '"trial version expired" exception will be thrown.
    Dim oClient
    Set oClient = CreateObject("EAGetMailObj.MailClient")
    oClient.LicenseCode = "TryIt"
    
    'To receive email from imap4 server, please change
    'MailServerPop3 to MailServerImap4 in MailServer constructor
    Dim oServer
    Set oServer = CreateObject("EAGetMailObj.MailServer")
    oServer.Server = sServer
    oServer.User = sUserName
    oServer.Password = sPassword
    oServer.SSLConnection = bSSLConnection
    oServer.Protocol = MailServerPop3
    
    'by default, the pop3 port is 110, imap4 port is 143,
    'the pop3 ssl port is 995, imap4 ssl port is 993
    'you can also change the port like this
    'oServer.Port = 110
    If oServer.Protocol = MailServerImap4 Then
        If oServer.SSLConnection Then
            oServer.Port = 993 'SSL IMAP4
        Else
            oServer.Port = 143 'IMAP4 normal
        End If
    Else
        If oServer.SSLConnection Then
            oServer.Port = 995 'SSL POP3
        Else
            oServer.Port = 110 'POP3 normal
        End If
    End If
    
 
    Dim leaveCopy
    leaveCopy =  True 'leave a copy of message on server.
    Dim downloadFolder
    downloadFolder = "c:\popdownload" 'download emails to this local folder.
    'send request to EAGetMail Service, then EAGetMail Service retrieves email in background and 
    'this method returns immediately.
    oClient.GetMailsByQueue oServer, downloadFolder, leaveCopy

End Sub

[Visual C++]
#include "eagetmailobj.tlh"
using namespace EAGetMailObjLib;
 
void ReceiveMail( 
        LPCTSTR sServer, 
        LPCTSTR sUserName,
        LPCTSTR sPassword,
        bool bSSLConnection)
{
    ::CoInitialize( NULL );
 
    const int MailServerPop3 = 0;
    const int MailServerImap4 = 1;
 
    try
    {
        IMailClientPtr oClient;
        oClient.CreateInstance( "EAGetMailObj.MailClient" );
 
        IMailServerPtr oServer;
        oServer.CreateInstance( "EAGetMailObj.MailServer" );
        
        // For evaluation usage, please use "TryIt" as the license code, otherwise the
        // "invalid license code" exception will be thrown. However, the object will expire in 1-2 months, then
        // "trial version expired" exception will be thrown.
        oClient->LicenseCode = _T("TryIt");
 
        oServer->Server = sServer;
        oServer->User = sUserName;
        oServer->Password = sPassword;
        
        INT nProtocol = MailServerPop3;
 
        oServer->Protocol = nProtocol;
        if( nProtocol == MailServerPop3 )
        {
            if( bSSLConnection )
            {
                oServer->Port = 995;
                oServer->SSLConnection = VARIANT_TRUE;
            }
            else
            {
                oServer->Port = 110;
            }
        }
        else
        {
            if( bSSLConnection )
            {
                oServer->Port = 993;
                oServer->SSLConnection = VARIANT_TRUE;
            }
            else
            {
                oServer->Port = 143;
            }
        }
 
        VARIANT_BOOL leaveCopy = VARIANT_TRUE; //leave a copy of message on server.
        LPCTSTR downloadFolder = _T("c:\\popdownload"");//download emails to this local folder
        //send request to EAGetMail Service, then EAGetMail Service retrieves email in background and 
        //this method returns immediately.
        oClient->GetMailsByQueue( oServer, downloadFolder, leaveCopy );

    }
    catch( _com_error &ep )
    {
        _tprintf( _T("ERROR: %s\r\n"),  (TCHAR*)ep.Description());
    }
 
    ::CoUninitialize();
}

Retrieve emails in schedule

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 in schedule, 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.

See Also

Using EAGetMail POP3 & IMAP4 Component
User Authentication and SSL Connection
Digital Signature and E-mail Encryption/Decryption
Parse Bounced Email (delivery-report)
Work with winmail.dat (TNEF Parser)
EAGetMail Namespace References
EAGetMail POP3 & IMAP4 Component Samples