[SalesForce] Sending HTML emails with inline images via SingleEmailMessage

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?

Best Answer

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.

Related Topic