0 votes

Hello,

I am reading email using IMAP and show Email text as html in a

.

*. The embedded images into HTML are not displaying, there display like an broken image icon not else.

Thank you.

by (850 points)
edited by
Please ask one question at a time.

1 Answer

0 votes

1.
In most cases HTML body of the message references images using special "cid:" protocol, that specifies Content-ID of the image that should be used:

This is our <strong>brand new</strong> logo: <br />
<img src="cid:logo@example.com" />

In such case actual image is embedded inside an email, as part of the mime tree, as an element related to HTML body and with content-disposition header set to inline.

Such image is available using IMail.Visuals or IMail.Attachments collection:

MimeData image = email.Visuals[@"logo@example.com"];

You can use IMail.GetBodyAsHtml(true) to get html with all images inlined using 'data:' URI scheme.

You can use IMail.SaveHtmlAs(@"c:\email.html") to save html and all images to the specified folder. When you invoke SaveHtmlAs all inline images (referenced using "cid:") are saved along with the html file, HTML is modified to reference local files.

2.
I can't really answer that, it's up to you how do you want to display them from web perspective.

I can answer how you can access attachments having IMail instance. IMail has several collections that may contain attachments:

IMail.Attachments – all attachments (includes Visuals, NonVisuals and Alternatives).
IMail.Visuals – visual elements, files that should be displayed to the user, such as images embedded in an HTML email.
IMail.NonVisuals – non visual elements, “real” attachments.
IMail.Alternatives – alternative content representations, for example ical appointment.

3.
You need to upload attachment to the web server first, then you can either use MailBuilder.AddAttachment(string path) and specify the tmp path of the uploaded file
-or-
Use MailBuilder.AddAttchment(byte[] data) if you have the attachment in memory.

MailBuilder.AddAttachement returns MimeData instance that can be further modified by setting FileName and/or ContentType.

by (297k points)
edited by
...