+1 vote

Is there a good example on how to display an eml file in an asp.net c# web page?
I am able to pull messages from my email server and save them as a .eml
To display, I can convert the .eml to an IMail.
When I display the body as HTML, the embedded images are not showing.
I need those and also need to allow the users to click on attachments from the .eml as well.
Any example to follow?
Thanks

by

1 Answer

0 votes
 
Best answer

HTML used in emails is a bit different than regular html, especially in a way how images are referenced. As images are in many cases attached to to the message, cid protocol is used to reference them:

<img src = 'cid:image1' />

What comes after "cid:" is the Content-ID of the referenced visual object.

This object must be attached to the email, and usually can be found in IMail.Visuals collection.

You have several options:

  1. Save all visuals elements to disk (or memory or database), parse and rewrite HTML, so each time cid: resource is referenced you reference your server:

    cid:image1 -> https://example.com/visualsprovider?id=image1

  2. Inline all images so base64 is used:

    <img src='data:image/jpeg;base64, LzlqLzRBQ...BASE64DATA' />

You can use IMail.SaveHtmlAs or IMail.GetBodyAsHtml methods with inlineVisuals parameter set to true for that purpose.

Hope this helps.

by (297k points)
...