0 votes
by (150 points)


It seems, that my customer sent me an EML file with attached documents, Rebex.Mail is unable to find.

This EML file is in "rebex-eml-attachment.zip" I uploaded on: {link removed}

My code snippet is below.

In this snippet I see, that "rebexMailDoc.Attachments.Count()" value is 0. But Microsoft Outlook shows me 3 attached PDF files if I try use it.

I use Rebex.Mail component version 6.0.8123.0

Please let me know if you have newest version of Rebex.Mail, that is able to extract attached documents from EML file I attached.


Const sSrcFile = "C:\In\7b. Bastion Capital confirmations - Danidan Capital 310714.eml"
Const sOutFolder = "D:\out"

        Dim rebexMailDoc = New Rebex.Mail.MailMessage

        For Each attFile In rebexMailDoc.Attachments
            Dim sDisplayFileName = attFile.DisplayName
            If String.IsNullOrEmpty(sDisplayFileName) Then
                Continue For
            End If

            Dim sAttFilePath = CombinePath(sOutFolder, sDisplayFileName)

    Catch ex As Exception
        Console.WriteLine("Error! Message: " + ex.Message)
    End Try
Applies to: Rebex Secure Mail

1 Answer

0 votes
by (62.7k points)


Please note that there are two collections where attached content can be located:
- MailMessage.Attachments
- MailMessage.Resources

The attached content is placed into a collection based on its appearance in the MIME structure.

The provided .eml file has following structure:

enter image description here

This corresponds to locating the .pdf files in the MailMessage.Resources collection (alongside the linked .png image, which is not considered as an attachment, it is an image inside the HTML body).

You expected the .pdf files to be located in the MailMessage.Attachments collection. In such case, the correct MIME structure should be like this:

enter image description here

Please, read the .pdf files from the MailMessage.Resources collection. Or ask the originator of the .eml file to create properly structured .eml file.

Microsoft Outlook has its own logic for showing attachments. You can do similar logic by yourself.
For example, you can move a resource to attachments, whose Content-ID is not referenced from mail BODY. Or you can move all non-image resources to attachments by default.