C# Receiving pop3 email with inline images and cid value

1.2k Views Asked by At

I am working to receive pop3 emails via OpenPop component. I am receiving emails from the server and saving to the sql database. At this point, there is no problem.

But today, I realized, some images are not showing on the richtextbox. This email's source code :

Original image file name : image001.jpg

Content-Type: image/jpeg; name="image001.jpg"
Content-Transfer-Encoding: base64
Content-ID: [email protected]

And

In html body, cid value : [email protected]

With above code, I am not living any problem. Because I am getting image file name from the CID value. (image001.jpg). I am getting image from the SQL server with the true image file name.

But, if we send the same email via Gmail web-interface;

Content-Type: image/jpeg; name="image001.jpg"
Content-Disposition: inline; filename="image001.jpg"
Content-Transfer-Encoding: base64
Content-ID: ii_iksd5tmd1_152f4c90885b6c5d

And we see on the richtextbox the CID value :

cid:ii_iksd5tmd1_152f4c90885b6c5d

Here is the problem.

CID value is not contains the file name information. So, I am not getting the image. The CID value is changing when the emails receiving from the Gmail.

In order to catch true image file name, what should I do?

Thanks so much.

3

There are 3 best solutions below

0
On

Use the following logic to get the file name:

If the Content-Disposition header exists, use the filename parameter value as the attachment file name. Otherwise fall back to using the name parameter value on the Content-Type header if that exists.

The Content-Id header value can be anything, all you can really expect from it is that it is a unique string within the context of the message.

Obviously the cid: URL in the HTML of the message refers to the Content-Id header value, so if you want to be able to reference the attachment at a later date after saving the attachments to disk, then you'll also need to save the Content-Id in the database record for the attachment.

0
On

Images used inline in HTML Mails do not necessarily have a "true filename". It is possible that they only use the CID. You should store the CID with the images in the database and then retrieve the image via the CID from the database to display it.

0
On

OpenPop results :

Content-Description : null
Content-ID : null
Content-Disposition : null

I am trying another web-interface and same results. For ex : Outlook web-interface

Examples :

HTML BODY in RichText

"img src="cid:ii_iksd5tlv0_152f4c90885b6c5d" height="398" width="530">
img src="cid:ii_iksd5tmd1_152f4c90885b6c5d" height="398" width="530">
​>

Original image file names : DSC00011.jpg and DSC00018.jpg