Using EAGetMail POP3 & IMAP ActiveX Object


Add Reference of EAGetMailObj ActiveX Object to Visual Basic 6 Project

To use EAGetMail POP3 & IMAP ActiveX Object in your project, the first step is "Add reference of EAGetMail ActiveX Object to your project". Please create/open your project with Visual Basic 6, then choose menu->"Project"->"References"->"EAGetMailObj ActiveX Object", and click "Open"->"OK", the reference of EAGetMail ActiveX Object will be added to your project, and you can start to use EAGetMail POP3 & IMAP ActiveX Object in your Visual Basic 6 Project.

Add Reference of EAGetMailObj ActiveX Object to Visual C++ Project

To use EAGetMail POP3 & IMAP ActiveX Object in your project, please copy "eagetmailobj.tlh" and "eagetmailobj.tli" to your Visual C++ Project folder. You can find those files in EAGetMail Installation Path\Samples_VSXXXX\pop3_imap4_simple.vcNative. You also need to add the following code in your VC++ header files:

        
#include "eagetmailobj.tlh"
using namespace EAGetMailObjLib;

Then you can start to use EAGetMail POP3 & IMAP ActiveX Object in your Visual C++ Project.

Add Reference of EAGetMailObj ActiveX Object to VBScript/ASP Project

You just need to install EAGetMail ActiveX Object on your machine, then you can use it directly.

Add Reference of EAGetMailObj ActiveX Object to Delphi Project

First of all, create a standard delphi project: select menu "Project" -> "Import Type Library", checked "EAGetMailObj ActiveX Object" and click "Create Unit". Then include "EAGetMailObjLib_TLB" in your project.

Deploying EAGetMail with Application

EAGetMail ActiveX Object is a COM object, you need to copy it to your target machine and run Regsvr32 "c:\my folder\eagetmailobj.dll" to register it as a COM object. Download EAGetMail installer and run it on your machine, the dll will be registered automatically.

If you want to distribute/deploy without EAGetMail installer.
1. copy eagetmailobj.dll to destination machine. (run-time file of EAGetMail ActiveX Object)
2. run "Regsvr32 [path]\eagetmailobj.dll" under dos prompt. (register EAGetMail ActiveX Object as com object)

Windows x64(AMD64)

For VBScript/ASP application on Windows x64 platform.
For Visual C++, Delphi application compiled to x64 native code.
Please use the dll in EAGetMail installation path\x64\eagetmailobj.dll (eagetmailobj.dll for x64). 
For Visual Basic 6.0 application, because it is always 32bit application, so it can work fine without EAGetMail ActiveX Object X64 File. 

Seperate builds of run-time dll for 32 and x64 platform

File Platform
Installation Path\EAGetMailObj.dll 32 bit
Installation Path\x64\EAGetMailObj.dll 64 bit

Send/Edit/Compose Email

EAGetMail ActiveX Object doesn't send, edit or compose email. To send, edit or compose email, please use EASendMail SMTP Component.

Example

[VisualĀ Basic 6.0, VBScript, Visual C++] The following example demonstrates how to receive email with EAGetMail POP3 & IMAP ActiveX Object, but it doesn't demonstrates the events and mail parsing usage. To get the full samples of EAGetMail, please refer to Samples section.

[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
        oClient.Connect oServer
        Dim infos
        infos = oClient.GetMailInfos()
        
        Dim i, Count
        Count = UBound(infos)
        For i = LBound(infos) To Count
            Dim info As EAGetMailObjLib.MailInfo
            Set info = infos(i)
            Dim oMail As EAGetMailObjLib.Mail
            Set oMail = oClient.GetMail(info)
            'Save mail to local
            oMail.SaveAs "d:\tempfolder\" & i & ".eml", True
        Next

        For i = LBound(infos) To Count
            oClient.Delete (infos(i))
        Next

        '' Delete method just mark the email as deleted,
        ' Quit method pure the emails from server exactly.
        oClient.Quit
        Exit Sub
ErrorHandle:
        ''Error handle
        MsgBox Err.Description
        
        oClient.Close
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
    

    oClient.Connect oServer
    Dim infos
    infos = oClient.GetMailInfos()
    
    Dim i, Count
    Count = UBound(infos)
    For i = LBound(infos) To Count
        Dim info
        Set info = infos(i)
        Dim oMail
        Set oMail = oClient.GetMail(info)
        'Save mail to local
        oMail.SaveAs "d:\tempfolder\" & i & ".eml", True
    Next

    For i = LBound(infos) To Count
        oClient.Delete (infos(i))
    Next

    '' Delete method just mark the email as deleted,
    ' Quit method pure the emails from server exactly.
    oClient.Quit
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;
            }
        }

        oClient->Connect( oServer );

        _variant_t arInfo = oClient->GetMailInfos();
        SAFEARRAY *psa = arInfo.parray;

        long LBound = 0, UBound = 0;
        SafeArrayGetLBound( psa, 1, &LBound );
        SafeArrayGetUBound( psa, 1, &UBound );
    
        INT count = UBound-LBound+1;
        for( long i = LBound; i <= UBound; i++ )
        {
            _variant_t vtInfo;
            SafeArrayGetElement( psa, &i, &vtInfo );
            
            IMailInfoPtr pInfo;
            vtInfo.pdispVal->QueryInterface(__uuidof(IMailInfo), (void**)&pInfo);

            IMailPtr oMail = oClient->GetMail(pInfo);
            TCHAR szFile[MAX_PATH+1];
            memset(szFile, 0, sizeof(szFile));
            ::wsprintf( szFile, _T("d:\\tempfolder\\%d.eml"), i );
            //save to local disk
            oMail->SaveAs( szFile, VARIANT_TRUE );
            oMail.Release();
        }

        
        for( long i = LBound; i <= UBound; i++)
        {
            _variant_t vtInfo;
            SafeArrayGetElement( psa, &i, &vtInfo );

            IMailInfoPtr pInfo;
            vtInfo.pdispVal->QueryInterface(__uuidof(IMailInfo), (void**)&pInfo);

            //delete email from server
            oClient->Delete( pInfo );
        }

        // Delete method just mark the email as deleted, 
        // Quit method pure the emails from server exactly.
        arInfo.Clear();
        oClient->Quit();
    }
    catch( _com_error &ep )
    {
        _tprintf( _T("ERROR: %s\r\n"),  (TCHAR*)ep.Description());
    }

    ::CoUninitialize();
}

See Also

User Authentication and SSL Connection
Digital Signature and E-mail Encryption/Decryption
Unique Identifier (UIDL) in POP3 and IMAP4 protocol
Parse Bounced Email (delivery-report)
Work with winmail.dat (TNEF Parser)
EAGetMail ActiveX Object References
EAGetMail POP3 & IMAP4 Component Samples