Keep inline attachment image links in HTML Mail's

Topics: Feature Requests
Sep 14, 2016 at 6:03 AM

Thanks for your awesome library.

I have a feature request concerning the parsing of html emails and inline images.

I want to show the images in a web application and unfortunately, the inline image tags with the ContentId source are removed and replaced by a string like "(Embedded image moved to file: pic23941.gif)".

Is there a flag or another possible solution to keep the image tags as they are in the mail message?

Thanks in advance!

Yours sincerely,
Sep 18, 2016 at 1:23 AM
I grepped around in the ImapX source code and cannot find any code that replaces img tags with a string like what you provided.

I suspect that what is happening is that you are grabbing the text/plain message body instead of the text/html message body.

That said, a browser control will not render img tags with a cid: source URL. In order to get those img tags to render properly, you'll need to use something like the HtmlPreviewVisitor mentioned at (scroll down a few paragraphs).

That example saves the referenced images off to a temp directory and references them using a file:// URL, but the other option is to embed the image data in the HTML like this:
string GetDataImageSrc (MimePart image)
    using (var output = new MemoryStream ()) {
        image.ContentObject.DecodeTo (output);
        return string.Format ("data:{0};base64,{1}", image.ContentType.MimeType, Convert.ToBase64String (output.GetBuffer (), 0, (int) output.Length));