Question:
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?
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:
http://www.example-code.com/ios/smtp_EmbedImage.asp
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.
Here are more details:
PNG:<br>
<img src="cid:part1.08060202.00060900@gmx.de" alt=""><br>
<br>
To show the image embedded within the text, I want to replace:
cid:part1.08060202.00060900@gmx.de
with:
pathToDocuments/Attachments/myImage.png
Here an example of a raw email with only the data shortened:
+OK Return-Path: xxxxxxxx@gmx.de Received: from mout.gmx.net ([212.227.15.15]) 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 ([10.1.76.27]) 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) [89.246.74.88] by mail.gmx.net (mp027) with SMTP; 29 Apr 2013 17:41:14 +0200 X-Authenticated: #3528779 X-Provags-ID: V01U2FsdGVkX1/WfY5UwVDWyX20EnbsLdIZ7dJ8zTqpez9fdz4CPS 2iBmqlMoWBlZ75 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; boundary="------------070605040208040605000000" 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 kZcgU/CXJ4bFHgyj+oFI4X19cOJVaPzg17oeyPHBJdl855ceud3s+WgLyFPvhFrrcMgxnEt . . . 6PPFpTHS3ghhEUYpL822GWy2E/02yZ4ov+9y9This 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
PNG:
PDF:
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:
PDF:
Cheers,
abu
</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--
--------------020401060503070003040704--
--------------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-- .
If you have a look at the MIME, you can see how it's nested:
multipart/mixed multipart/alternative text/plain multipart/related text/html image/png -- end multipart/related -- end multipart/alternative application/pdf -- 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.
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.