Archived Forum Post

Index of archived forum posts


Problems with AddRelatedFile2

Jul 25 '17 at 15:57

I'm trying to send emails with a signature, it's a JPG file, and I want to embed in email foot.

I'm writing one cid in Html code img src='cid:Signature'

And after I make ::oMail:AddRelatedFile2( cSignatureFile, "Signature" )

However the email is received, the file is attached, but there is a "missing image" block in the body where the image is supposed to be in the body of the mail?

Wath's the problem.


How can the relative addressing work? Assuming the example is correct... or what else could be wrong?


Accepted Answer

There are two ways for HTML to reference an image (or perhaps a CSS file) that is located elsewhere within the MIME of the email (under the multipart/related enclosure -- thus they are called "related items" rather than attachments. Attachments are located in the MIME under the multipart/mixed enclosure).

  1. The URI in the HTML can be a "cid:{content-id}" URI. In this case, the {content-id} must match the value of the Content-ID header field in the MIME sub-part containing the image. The addRelatedFile method is for adding a related file using a Content-ID (because it returns the Content-ID string that should be placed in the HTML.
  2. Alternatively, the URI in the HTML can be a URL, path, etc, and it must match the value of the Content-Location header field for the MIME sub-part that contains the image data. The addRelatedFile2 method is or adding a related item using Content-Location. It allows for you to specify the Content-Location in the 2nd argument, which is appropriately named "filenameInHtml". See the online reference documentation.


According to this example it shows this:

//  For whatever reason, the iPhone's email program requires
//  images in HTML to be referenced by Content-ID.  Therefore,
//  we must add the image like this:
const wchar_t *contentIdStarfish = email.addRelatedFile(L"qa_data/jpg/starfish.jpg");
if (email.get_LastMethodSuccess() != true) {

//  The src attribute for the image tag is set to the contentIdStarfish:
CkStringBuilderW sbHtml;
sbHtml.Append(L"<html><body><p>This is an HTML email with an embedded image.</p>");
sbHtml.Append(L"<p><img src=\"cid:CONTENT_ID_STARFISH\" /></p></body></html>");
int numReplacements = sbHtml.Replace(L"CONTENT_ID_STARFISH",contentIdStarfish);