Friday, December 17, 2010

Can't find all the attachments in .EML file?

Using CDOSYS.DLL is a very convenient way to parse and extract content and attachments from an EML file. However, embedded images in the HTML part of the email do not appear as attachments.

Solution: enumerate the BodyParts and look for BodyParts with a filename: this includes all the attachments and embedded images.  The syntax is a little tricky, but BodyParts work just the same as Attachments.


        Dim bodypart_count = Msg.BodyPart.BodyParts.Count
        Dim i As Integer = 0
        For i = 1 To bodypart_count
             If Msg.BodyPart.BodyParts(i).FileName <> "" Then
                attachment_count += 1
            End If
        Next

No comments:

Post a Comment