How to display html email address with embedded images (cid)?

I store emails and their attachments in a database. I am using WPF WebBrowser and the NavigateToString method to display the html message file. It works, but when emails use embedded images with a content identifier (cid), I cannot display them. I saved all inline images as attachments when I save emails in the database. I could create and store images in temporary files of the current user and replace the cid links with the absolute path on the user's disk, but I think this is not the best way ...

Do you have any ideas?

+6
source share
1 answer

I finally found a good way:

I replaced the cid links with all images with base64 image data (RFC 2557) as follows:

<img src="data:image/png;base64,RAAAtuhhx4dbgYKAAA7...more data....." alt="test"> 

You can use the following code to generate a base64 string:

 string base64Str = Convert.ToBase64String(File.ReadAllBytes(@"C:\Temp\test.png")); 

Notes: does not work with IE6

+16
source

Source: https://habr.com/ru/post/892108/


All Articles