Sample code for 30+ languages & platforms
Xojo Plugin 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 Xojo Plugin Downloads

Xojo Plugin
Dim success As Boolean
success = False

//  Assumes Chilkat is unlocked. See Global Unlock Sample.

Dim email As New Chilkat.Email
success = email.LoadEml("with-attachments.eml")
If (success <> True) Then
    System.DebugLog(email.LastErrorText)
    Return
End If

Dim filename As New Chilkat.StringBuilder
Dim mediaType As New Chilkat.StringBuilder
Dim found As Boolean
found = False
Dim i As Int32
i = 0
While (i < email.NumAttachments)
    success = filename.SetString(email.GetAttachmentFilename(i))
    success = mediaType.SetString(email.GetAttachmentContentType(i))
    If ((filename.ContentsEqual("agenda.csv",False) = True) And (mediaType.ContentsEqual("text/csv",False) = True) And (found = False)) Then
        Dim data As New Chilkat.BinData
        success = email.GetAttachmentBd(i,data)
        If (success <> True) Then
            System.DebugLog(email.LastErrorText)
            Return
        End If

        success = data.WriteFile("received-agenda.csv")
        If (success <> True) Then
            System.DebugLog("Failed: data.WriteFile.")
            Return
        End If

        System.DebugLog("Saved attachment: " + Str(data.NumBytes) + " bytes.")
        found = True
    End If

    i = i + 1
Wend
If (found <> True) Then
    System.DebugLog("No matching attachment.")
End If

i = 0
While (i < email.NumRelatedItems)
    System.DebugLog("Related: " + email.GetRelatedContentType(i) + "  Content-ID: " + email.GetRelatedContentID(i))
    i = i + 1
Wend