“Content-ID” in email attachments

I need to add image(no public) in a email. Initially I tried "Inline Embedding" but gmail, ... block the images, now I'm trying to add with "CID Embedded Images"

Exist some way to add the Content-ID in the attached files.

 $params["attachments"][] = array( 'fullPath' =>$output, 'Content-ID' => 'attachementsignature' //Something like that ); 

Info "Inline Embedding", "CID Embedded Images" in https://sendgrid.com/blog/embedding-images-emails-facts/

@Sudesh After apply the patch, I used a token, because i needed a custom field in the image, maybe works for you(the answer don't fit in comment :S)

The cid require a mail format for example foo@ba.org

hook_civicrm_tokenValues( &$values,$cids, $job = null,$tokens = array(), $context = null ) { ...$values[$key]["xxx.app_signature"] = '<img alt="Embedded Image" src="cid:foo@ba.org" >' . '<tagimagetoken>' .$config->customFileUploadDir . $result_image["uri"] . '</tagimagetoken>';  And later replace the token with correct value in the mail hook hook_civicrm_alterMailParams(&$params, $context) {$regex = "/<\s*tagimagetoken[^>]*>([^<]*)<\s*\/\s*tagimagetoken\s*>/";
preg_match_all($regex,$params["html"], $output); if(isset($output[1][0])) {
$params["html"] = preg_replace ($regex , "" ,  $params["html"]);$params["attachments"][] =  array(
'fullPath' => $output[1][0], 'content_id' => "foo@ba.org", 'c_type' => "image/png", 'is_file' => TRUE, 'is_image' => TRUE, ); } }  And in the email put the token • Ok. Correct me if I misunderstand, but, you insert this custom token whenever you want an in-line image in the HTML email and the token is replaced in the hook. So, how does it work when you now composing the email in CKEditor and you want to add some in-line image to the email? – Sudesh Nov 18 '15 at 9:47 • This solutions it's creating a token, when you create a token later appear when you compose a email clicking in "Insert token". If the image that you want add is not in the contact(fixed for all mails). You can add directly in the email with source "<img alt="Embedded Image" src="cid:foo@ba.org" >" and only make the step "hook_alterMailParams." inserting the$params["attachments"][]. – rubofvil Nov 20 '15 at 10:17

In package Mail exist the method "addHTMLImage" https://github.com/civicrm/civicrm-packages/blob/master/Mail/mime.php#L332

The patch fix in the actions contact "Send a email"(not in component civimail).https://github.com/rubofvil/civicrm-core/commit/aa11061457da792f6678786ede446422fc450e36

I'm sending the parameters in the hook_civicrm_alterMailParams

$params["attachments"][] = array( 'fullPath' =>$output[1][0],
'content_id' => "attachmentsignature",
'c_type' => "image/png",
'is_file' => TRUE,
'is_image' => TRUE,
);


Next Issue: With the patch CiviMail put in content-id the email in some point. The image it's attached inline but with incorrect content-id.

• Hi rubofvil, have you manged to get around the incorrect content ID? I'm also wanting to embed images using content ID for our mail campaigns using Civimail. WIthout using CID, Outlook will always block these images. Mail clients like SendinBlue use CID and Outlook displays images perfectly with images sent from SendinBlue. – Sudesh Nov 13 '15 at 10:07
• @Sudesh, I answered in another answer, here don't fit the solution – rubofvil Nov 16 '15 at 22:22
• do you have a full patch that can be applied with the with the Token and the mail hook? Would you be able to share your entire source changes? We are really desperate on our side to get this working? I would really appreciate your help? – Sudesh Jan 14 '16 at 8:55