+2 votes

I am creating a Internal webmail for my office. Everything is working fine.

But only problem is when I am using email.SaveHtmlAs() it is storing all the embedded images to disk also and able to see the images when loading the html file but I need to store the html data in database so I am using email.GetBodyAsHtml() and I am unable see the embedded images the path's are like

cid:2.28876446561.3303816762000988278.145db22ce1c__inline__img__src

so i their any option to show embed images while storing data in database.

by
edited by

1 Answer

0 votes

when I am using email.SaveHtmlAs() it is storing all the embedded images to disk

Yes, this is exactly what this method is supposed to be doing:
It extracts images from the email and saves them to disk,
it modifies html data so all cid: references point to files on disk instead,
finally it saves modified html to file.

the path's are like
cid:2.28876446561.3303816762000988278.145db22ce1cinlineimg__src

This is not a path, it's a content id reference.

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" and content-id set to "logo@example.com".

You can read this article to learn more about cid protocol and how images are referenced from email's HTML.

i[s] their any option to show embed images while storing data in database.

You need to use IMail.Visuals collection and save all elements stored there to the database along with their content ids.

by (301k points)
As i understand from your article I need to store the file to databse  with content id's ok I f I will choose to store the Image to filesystem then I need to use
foreach (MimeData mime in email.Visuals)
            {
                mime.Save(@"c:\" + mime.SafeFileName);
            }
so it is saving the data as 1,2,3,4,5,6 not the actual cid so how to replace the cid path to the physical path, I am very poor in English so please try to understand and help.
Use IMail.SaveHtmlAs - it saves all to disk and replaces cid. If you need to replace cid yourself - it is not a simple task. The easiest way would be probably to use "cid:"+cid value and string replace/regex.
...