0 votes
by (140 points)
edited

Greetings,

I'm parsing message in RTF format which was sent from MS outlook 2010. Message contains 2 embedded images.

In HTML body I can see that their source contains some kind of Id:
(img border=0 src="cid:embedded-rtf-attachment-id0@rebex.net")
(img border=0 src="cid:embedded-rtf-attachment-id1@rebex.net")

How can I retreive those images from Linked Resources collection using "cid:embedded-rtf-attachment-id0@rebex.net"?

Can I use MailMessage.Resource[0] and MailMessage.Resource[1] presuming that "cid:embedded-rtf-attachment-id0" and "cid:embedded-rtf-attachment-id1" are indexes from this collection?

Thank you.

Applies to: Rebex Secure Mail

2 Answers

+1 vote
by (58.9k points)
edited

Hello

you can retrieve the LinkedResource corresponding to "cid:embedded-rtf-attachment-id0@rebex.net" from the BodyHtml like this:

        MailMessage mail = new MailMessage();
        //...
        mail.Load("mail.eml");
        //...
        foreach (LinkedResource resource in mail.Resources)
        {
            if (resource.ContentId != null && resource.ContentId.Id == "embedded-rtf-attachment-id0@rebex.net") // without "cid:"
            {
                // this is the LinkedResource corresponding to "cid:embedded-rtf-attachment-id0@rebex.net"
                Console.WriteLine(resource.ContentString);
            }
        }

Parsing the index from the Content-ID is definitely not a good idea. So please use the above solution.

by (140 points)
edited

Tomáš, Thank you.

by (140 points)
edited

Tomáš,

Just checked solution you've proposed.

It works fine for mail in HTML format. But it seems this solution didn't work for RTF letters: "resource.ContentId" is null for all RTF attachments.

Could it be mail server or mail client issue? Can you confirm your solution works for RTF mail?

Thank you.

by (140 points)
edited

Just a little clarifation: Resources are present in collection, but their ContentId is null. So it looks that I'm unable to get specific resource from collection using that way you've proposed.

+1 vote
by (58.9k points)
edited

To make it clear: ContentId of attachments and linked resources is set by the mail client which creates the mail and it can be anything. There is no guarantee about it.

However, Rebex offers a new advanced feature which enables transformation of MS Outlook format messages (which contains no HTML) into more user friendly format. During this proccess, a HTML body is converted from rtf and if there were embedded images, we add ContentId in the special format mentioned above) and reference the images from the HtmlBody.

So a MailMessage which contains "cid:embedded-rtf-attachment-id{index}@rebex.net" within its HtmlBody will definitely contain an image in the mail.Resources collection. The other implication is not valid. The cid has to be in the exact specified format ending with @rebex.net.

Currently only embedded images (jpg, bmp, png or gif) are referenced from the Rebex generated HtmlBody). Other embedded attachments are only referenced in the html textually as <<attachment.filename>> and their ContentId can be null (and you can find them in mail.Attachments).

by (140 points)
edited

Thank you for your answer.

...