Sample code for 30+ languages & platforms
AutoIt Requires Chilkat v11.0.0+

Preview POP3 messages and download a complete email

See more Email Object Examples

Read a short preview for each of up to five messages into an EmailBundle, print their subjects, and download the complete first entry into a separate Email. Configure a POP3 account that supports UIDL and TOP. All messages stay on the server.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

;  Assumes Chilkat is unlocked. See Global Unlock Sample.

$oMail = ObjCreate("Chilkat.MailMan")
$oMail.MailHost = "pop.example.com"
$oMail.MailPort = 995
$oMail.PopSsl = True
$oMail.RequireSslCertVerify = True
$oMail.PopUsername = "MAIL_USER"
$oMail.PopPassword = "MAIL_PASSWORD"
$oPreviews = ObjCreate("Chilkat.EmailBundle")
;  Keep the messages and request minimal previews. Range indexes are zero-based and inclusive.
$bSuccess = $oMail.FetchRange(True,True,0,0,4,$oPreviews)
If ($bSuccess <> True) Then
    ConsoleWrite($oMail.LastErrorText & @CRLF)
    Exit
EndIf

If ($oPreviews.MessageCount = 0) Then
    ConsoleWrite("There are no messages to preview." & @CRLF)
    $bSuccess = $oMail.Pop3EndSession()
    If ($bSuccess <> True) Then
        ConsoleWrite($oMail.LastErrorText & @CRLF)
        Exit
    EndIf

    Exit
EndIf

$oHeader = ObjCreate("Chilkat.Email")
Local $i = 0
While ($i < $oPreviews.MessageCount)
    $bSuccess = $oPreviews.EmailAt($i,$oHeader)
    If ($bSuccess <> True) Then
        ConsoleWrite($oPreviews.LastErrorText & @CRLF)
        Exit
    EndIf

    ConsoleWrite($oHeader.Uidl & "  " & $oHeader.Subject & @CRLF)
    $i = $i + 1
Wend
;  A UI could use its selected row here. FetchFull uses the preview's POP3 identity.
$bSuccess = $oPreviews.EmailAt(0,$oHeader)
If ($bSuccess <> True) Then
    ConsoleWrite($oPreviews.LastErrorText & @CRLF)
    Exit
EndIf

$oEmail = ObjCreate("Chilkat.Email")
$bSuccess = $oMail.FetchFull($oHeader,$oEmail)
If ($bSuccess <> True) Then
    ConsoleWrite($oMail.LastErrorText & @CRLF)
    Exit
EndIf

$bSuccess = $oMail.Pop3EndSession()
If ($bSuccess <> True) Then
    ConsoleWrite($oMail.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("Full message: " & $oEmail.Subject & "  Files: " & $oEmail.NumAttachments & @CRLF)

$bSuccess = $oEmail.SaveEml("pop-received.eml")
If ($bSuccess <> True) Then
    ConsoleWrite($oEmail.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("Saved pop-received.eml." & @CRLF)