Visual Basic 6.0 Requires Chilkat v11.0.0+
Visual Basic 6.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 Visual Basic 6.0 Downloads
Dim success As Long
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim email As New ChilkatEmail
success = email.LoadEml("with-attachments.eml")
If (success <> 1) Then
Debug.Print email.LastErrorText
Exit Sub
End If
Dim filename As New ChilkatStringBuilder
Dim mediaType As New ChilkatStringBuilder
Dim found As Long
found = 0
Dim i As Long
i = 0
Do While (i < email.NumAttachments)
success = filename.SetString(email.GetAttachmentFilename(i))
success = mediaType.SetString(email.GetAttachmentContentType(i))
If ((filename.ContentsEqual("agenda.csv",0) = 1) And (mediaType.ContentsEqual("text/csv",0) = 1) And (found = 0)) Then
Dim data As New ChilkatBinData
success = email.GetAttachmentBd(i,data)
If (success <> 1) Then
Debug.Print email.LastErrorText
Exit Sub
End If
success = data.WriteFile("received-agenda.csv")
If (success <> 1) Then
Debug.Print "Failed: data.WriteFile."
Exit Sub
End If
Debug.Print "Saved attachment: " & data.NumBytes & " bytes."
found = 1
End If
i = i + 1
Loop
If (found <> 1) Then
Debug.Print "No matching attachment."
End If
i = 0
Do While (i < email.NumRelatedItems)
Debug.Print "Related: " & email.GetRelatedContentType(i) & " Content-ID: " & email.GetRelatedContentID(i)
i = i + 1
Loop