I have a requirement to send inline images in HTML email using SingleEmailMessage.

I seem to be stopped by an unresolvable problem caused by a gap in the Salesforce API.

Inline images require me to use a Content Id of the embedded image as the src of the image:

<img src="cid:[somerandomstring]">

And to attach the image to the email as a file attachment with the mime content id the same as I used in the img src attribute.

Unfortunately Salesforce does not seem to provide me with a property by which I can set the content ID of an attached file (it lets me pick the filename and interesting a boolean flag indicating if the image is 'inline').

Has anyone solved this problem before without resorting to a Amazon SES or Sendgrid callout?


A workarround could be to send real inline images: <img src="data:image/png;base64,DATA">. This would work for small images, otherwise the heap size might be a problem. A plus: the e-mail is shown without attachments in most of the e-mail-clients.

| improve this answer | |
  • has this solution been tried? Is there a recommended best practice? – akaphenom Dec 10 '14 at 20:09

I tried using the approach. These images did not display in Gmail or Outlook however if you saved the email as a html file the images displayed.

The only option that doesn't use Amazon SES or Sendgrid is to have Salesforce expose a Content-Id property that we can set.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.