Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I store emails and their attachments in a database. I'm using a WPF WebBrowser and the NavigateToString method to display the html body of emails. It works but when emails use embedded images with a content id (cid), i can't display them. I saved all embedded images as attachments when i save emails in database. I could create and store images in temporary files of the current user and replace cid references with an absolute path on user's disk but i think it's not the best way...

Have you got some ideas ?

like image 772
Nico Avatar asked Jul 06 '11 08:07

Nico


People also ask

How do I embed an image in an HTML email?

To attach an image, you need to have the encoding scheme of the image you want to attach. This is the base64 string of the picture. You can get this by right-clicking on the image you want to attach, copy the image address, and paste it into the HTML text. The recipient will have a preview of when they open the email.

What is CID HTML?

CID embedded images (inline images) CID images work by attaching the image to the email you're sending and then using standard HTML image tags that reference that image to eventually embed it in the email when the user opens it.

How do you embed an image in HTML?

The HTML <img> tag is used to embed an image in a web page. Images are not technically inserted into a web page; images are linked to web pages. The <img> tag creates a holding space for the referenced image. The <img> tag is empty, it contains attributes only, and does not have a closing tag.


1 Answers

I finally found a good way :

I replaced the cid references of all images with base64 image data (RFC 2557) like this :

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

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

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

Remarks : doesn't work with IE6

like image 144
Nico Avatar answered Sep 21 '22 23:09

Nico