Jump to content

Using EAGetMail in AutoIT


Recommended Posts

This page explains it in detail.
When installing EAGetMail on my machine I noticed a COM DLL file named "EAGetMailObj.dll".
The help file explains how to use it in VBS and VC++.

Here's the VBS code:

Sub ReceiveMail( _
ByVal sServer, _
ByVal sUserName, _
ByVal sPassword, _
ByVal bSSLConnection)
    
    Const MailServerPop3 = 0
    Const MailServerImap4 = 1
    Const MailServerEWS = 2
    Const MailServerDAV = 3

    '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 to MailServer.Protocol

    'To receive email with Exchange Web Service, please change
    'MailServerPop3 to MailServerEWS to MailServer.Protocol

    'To receive email with Exchange WebDAV, please change
    'MailServerPop3 to MailServerDAV to MailServer.Protocol

    'Exchange Server supports POP3/IMAP4 protocol as well, but in Exchange 2007
    'or later version, POP3/IMAP4 service is disabled by default. If you don't want to use POP3/IMAP4
    'to download email from Exchange Server, you can use Exchange Web Service(Exchange 2007/2010 or
    'later version) or WebDAV(Exchange 2000/2003) protocol.
    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)
        
        MsgBox "UIDL: " & info.UIDL
        MsgBox "Index: " & info.Index
        MsgBox "Size: " & info.Size
        'For POP3/Exchange Web Service/WebDAV, the IMAP4MailFlags is meaningless.
        MsgBox "Flags: " & info.IMAP4Flags 
        'For POP3, the Read is meaningless.
        MsgBox "Read: " & info.Read
        MsgBox "Deleted: " & info.Deleted
                    
        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

Could anyone help me to convert the code to AutoIT

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

Sure ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

No joke. Just a reply to your question :)

We can help you to translate the code. But first we need to know where your problem is.

Or do you expect us to translate the code for you?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

The problem is... creating the object.

When using:

$oClient = ObjCreate("EAGetMailObjLib.MailClient")
$iError = @error
If $iError <> 0 Then
    MsgBox(16, "Error", "@error = " & $iError)
    ClipPut($iError)
    Exit
EndIf

It gives me the error "-2147221005".

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

Could you please add a COM error handler as described in ObjEvent to get full error information?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Does it work for you when you run the VBS code?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Could you please add a COM error handler as described in ObjEvent to get full error information?

$oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
$oClient = ObjCreate("EAGetMailObjLib.MailClient")

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

Gives me:

Obj.au3 (2) : ==> COM Error intercepted !
    err.number is:      0x800401F3
    err.windescription: Invalid class string

    err.description is:     
    err.source is:      
    err.helpfile is:    
    err.helpcontext is:     27797608
    err.lastdllerror is:    1008
    err.scriptline is:  2
    err.retcode is:     0x01A82A70

Does it work for you when you run the VBS code?

Yes, the VBS code works.

Edited by DatMCEyeBall

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

err.windescription: Invalid class string

Your code: ("EAGetMailObjLib.MailClient")

VBS code: ("EAGetMailObj.MailClient")

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...