login about faq

The GetAttachmentContentID is always returning an empty string. All other Methods in attachment concerning methods I have used so far are working fine (getFilename, getContentType, getData…). I need the content ID to replace it within the HTML body with the path to the actual file, to embed the image in the text. Maybe this is the wrong approach for this task using Chilkat?

asked Apr 29 '13 at 12:24

chilkat's gravatar image

chilkat ♦♦

I think you might be going about it wrong.

Images that are purely part of an HTML email because they are part of the HTML body composition are not actually attachments. They are "related" items. An HTML IMG tag can reference the image data contained within the email itself in one of two ways -- via a Content-ID, or by Content-Location. I recommend using the Content-Location. See this example:


If you wish to instead use a Content-ID (a "CID" reference in the SRC attribute of the IMG tag), then you would add the related item via the AddRelatedFile or AddRelatedData methods, each of which returns the Content-ID it generated for the related item.

Finally, the fact that GetAttachmentContentID returned an empty string means that the MIME sub-part for that attachment did not have a Content-ID header.


answered Apr 29 '13 at 12:29

chilkat's gravatar image

chilkat ♦♦

Here are more details:

  • I'm downloading an email via POP3. AFAIKS, the Content-ID header is valid. Find the complete raw email below.
  • I'm displaying the HTML body. Part of the body is:

PNG:<br> <img src="cid:part1.08060202.00060900@gmx.de" alt=""><br> <br>

  • I saved the image before as a file myImage.png
  • To show the image embedded within the text, I want to replace:




Here an example of a raw email with only the data shortened:

Return-Path: xxxxxxxx@gmx.de
Received: from mout.gmx.net ([]) by mx-ha.gmx.net (mxgmx009) with
 ESMTP (Nemesis) id 0MIzJh-1UUvSN3KaP-002Tly for xxxxxxxx@gmx.de; Mon, 29
 Apr 2013 17:41:14 +0200
Received: from mailout-de.gmx.net ([]) by mrigmx.server.lan
 (mrigmx001) with ESMTP (Nemesis) id 0Lflzw-1Upyng1zS6-00pMkn for
 xxxxxxxx@gmx.de; Mon, 29 Apr 2013 17:41:14 +0200
Received: (qmail invoked by alias); 29 Apr 2013 15:41:14 -0000
Received: from unknown (EHLO Admin-Admins-Mac-mini.local) []
  by mail.gmx.net (mp027) with SMTP; 29 Apr 2013 17:41:14 +0200
X-Authenticated: #3528779
X-Provags-ID: V01U2FsdGVkX1/WfY5UwVDWyX20EnbsLdIZ7dJ8zTqpez9fdz4CPS
Message-ID: 517E9499.8090305@gmx.de
Date: Mon, 29 Apr 2013 17:41:13 +0200
From: Peter Falk xxxxxxxx@gmx.de
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130328 Thunderbird/17.0.5
MIME-Version: 1.0
To: Andreas Buff xxxxxxxx@gmx.de
Subject: TB: Attachments
Content-Type: multipart/mixed;
X-Y-GMX-Trusted: 0
Envelope-To: xxxxxxxx@gmx.de
X-GMX-Antispam: 0 (Mail was not recognized as spam); Detail=V3;
X-GMX-Antivirus: 0 (no virus found)
X-UI-Filterresults: notjunk:1;V01:K0:GBFGcQHllV8=:U1gb2Ir98My3uRl0gRwB7Q

This is a multi-part message in MIME format.

Content-Type: multipart/alternative; boundary="------------020401060503070003040704"

--------------020401060503070003040704 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit



Cheers, abu

--------------020401060503070003040704 Content-Type: multipart/related; boundary="------------090302040100090406030603"

--------------090302040100090406030603 Content-Type: text/html; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit

<html> <head>

<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">

</head> <body text="#000000" bgcolor="#FFFFFF"> PNG:


</body> </html>

--------------090302040100090406030603 Content-Type: image/png; name="dehijjjb.png" Content-Transfer-Encoding: base64 Content-ID: part1.08060202.00060900@gmx.de Content-Disposition: inline; filename="dehijjjb.png"

iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAahElEQVR42u2ceVBUZ9b/P3Q3 a9PsS7PJJhgQWVwjGBOX6CQRY4hxw9FknEyNmTjECUkmk6kYa7JYM5VY2WYhZUw0iZq4RI2R . . . 5Ens7e3x8fHh3nvvpaWlBZPJhK2tLaWlpRQXF3Po0CHzPU2YMMGsb+C5tFotXV1dREVFUVdX R2NjI2VlZaSnp7Nu3Tosef6R6H8AULLkbwpX0BEAAAAASUVORK5CYII= --------------090302040100090406030603--


--------------070605040208040605000000 Content-Type: application/pdf; name="PDF.pdf" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="PDF.pdf"

JVBERi0xLjMKJcTl8uXrp/Og0MTGCjQgMCBvYmoKPDwgL0xlbmd0aCA1IDAgUiAvRmlsdGVy IC9GbGF0ZURlY29kZSA+PgpzdHJlYW0KeAEVjD0OgCAUxnZP8Z0AHv+wu7jJ5GwIg4moEL2/ kK5tKyIqhIfQTBORhDEBXigm0TI2XOBrbik/77efaEe3h0EdJYlpF9TIpSXmLKkpFfClCMx3 . . . IDEgMCBSIC9JRCBbIDxlZDMxMjhiZGJmZDFhNmZkZWMwMGU3YTI3YmU2NzU0Yz4KPGVkMzEy OGJkYmZkMWE2ZmRlYzAwZTdhMjdiZTY3NTRjPiBdID4+CnN0YXJ0eHJlZgoyNDI2NAolJUVP Rgo= --------------070605040208040605000000-- .


answered Apr 29 '13 at 13:05

abu's gravatar image


edited Apr 29 '13 at 13:22

If you have a look at the MIME, you can see how it's nested:

        -- end multipart/related
    -- end multipart/alternative
-- end multipart/mixed

This is a typical and correct MIME structure. The true attachment is the application/pdf. The "related item" is the image/png. Call GetRelatedContentID instead of GetAttachmentContentID.


answered Apr 29 '13 at 13:27

chilkat's gravatar image

chilkat ♦♦

Thank you so much for your fast and useful answers.

I isolated the issue:

GetAttachmentContentID: always returns an empty string, iterating through attachments and iterating through related items.

GetRelatedContentID is working for attachments and for related items.


answered Apr 29 '13 at 13:34

abu's gravatar image


edited Apr 30 '13 at 06:02

Yes, that makes sense. Have a look at the MIME. There is no "Content-ID" header for the attachment. If the Content-ID header is not there, then there is no content-id. This is normal for an attachment. It's also possible for a related item. It does not indicate an error.

(Apr 30 '13 at 10:39) chilkat ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Apr 29 '13 at 12:24

Seen: 3,140 times

Last updated: Apr 30 '13 at 10:39

powered by OSQA