+1 vote

I am using the Mail.dll component to receive IMAP email in within my database application and it works very well with the exception that there does not appear to be a way to embed an image source into the HTML content of a message.

Essentially what I have is an application running on a single machine reading e-mails.

When an e-mail arrives, I extract the content and create rows in various database tables. Images are stored within my database, as is the HTML using IMail.SaveHtmlAs. This all works as expected.

The problem is that when that e-mail content is retrieved from within the database on say another machine, the image source appears to reference an image that is not available locally.

Is there functionality within Mail.dll to embed the mimedata/encoded image into the HTML file itself?

by (8.8k points)

1 Answer

0 votes
 
Best answer

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.

Invoking Imap.GetMessageByUID method is going to download
entire email message, including all images. This makes message bigger,
but images don't need to be stored on your web server (remember that
emails tend to be archived for years).

Programmatically image files are available through IMail.Visuals and IMail.Attachments collections.

When you invoke SaveHtmlAs all inline images (referred using cid:) are
saved along with the HTML file, HTML is modified to reference local
files (relative paths are used).

You should save HTML along with all those images (IMail.Visuals).

by (301k points)
selected by
...