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

Find and save an attachment and list inline images

See more Email Object Examples

Find an attachment by filename and media type, then save its decoded bytes to a path you choose. Enumerate inline resources separately to read their Content-IDs.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

;  Assumes Chilkat is unlocked. See Global Unlock Sample.

$oEmail = ObjCreate("Chilkat.Email")
$bSuccess = $oEmail.LoadEml("with-attachments.eml")
If ($bSuccess <> True) Then
    ConsoleWrite($oEmail.LastErrorText & @CRLF)
    Exit
EndIf

$oFilename = ObjCreate("Chilkat.StringBuilder")
$oMediaType = ObjCreate("Chilkat.StringBuilder")
Local $bFound = False
Local $i = 0
While ($i < $oEmail.NumAttachments)
    $oFilename.SetString($oEmail.GetAttachmentFilename($i))
    $oMediaType.SetString($oEmail.GetAttachmentContentType($i))
    If (($oFilename.ContentsEqual("agenda.csv",False) = True) And ($oMediaType.ContentsEqual("text/csv",False) = True) And ($bFound = False)) Then
        $oData = ObjCreate("Chilkat.BinData")
        $bSuccess = $oEmail.GetAttachmentBd($i,$oData)
        If ($bSuccess <> True) Then
            ConsoleWrite($oEmail.LastErrorText & @CRLF)
            Exit
        EndIf

        $bSuccess = $oData.WriteFile("received-agenda.csv")
        If ($bSuccess <> True) Then
            ConsoleWrite("Failed: data.WriteFile." & @CRLF)
            Exit
        EndIf

        ConsoleWrite("Saved attachment: " & $oData.NumBytes & " bytes." & @CRLF)
        $bFound = True
    EndIf

    $i = $i + 1
Wend
If ($bFound <> True) Then
    ConsoleWrite("No matching attachment." & @CRLF)
EndIf

$i = 0
While ($i < $oEmail.NumRelatedItems)
    ConsoleWrite("Related: " & $oEmail.GetRelatedContentType($i) & "  Content-ID: " & $oEmail.GetRelatedContentID($i) & @CRLF)
    $i = $i + 1
Wend