I have a custom html template with an image tag like:

<img src="{!companyLogo}" />

Then, in my controller that sends emails, I get the body of the custom html email template and replace that fake merge field that is used as a variable with:

htmlBody = htmlBody.replace('{!companyLogo}', Url.getSalesforceBaseUrl().getProtocol() + '://'+System.Url.getSalesforceBaseUrl().getHost().remove('-api')+'/servlet/servlet.ImageServer?id='+logoDocs[0].Id+'&oid='+UserInfo.getOrganizationId());

Where logoDocs is a document that contains an image that is retrieved by the following query:

List<Document> logoDocs = [SELECT Id, Name, Body, LastModifiedDate, ContentType, Type FROM Document WHERE Name = 'CompanyLogo'];

However, nothing shows up in the email. There is a prompt to view/download attached images, so it seems to recognize an image is there, but nothing shows up. Looking at the email html, I see the google proxy server url they gave the document... but it seems like that may have broken it and then the image is no longer found.

I get no image in Gmail, then I get the broken image link symbol in Outlook.

My query definitely finds the Document and gets the correct info from it by the query, based on my debug logs, so it has the right Id, and my org Id I put in the URL is also correct.

I am not getting why the image won't show up in emails. Does anyone know how to get an image that is in your Salesforce documents in a custom HTML email template, and have it show up in the email?

(I have tried using FileDownload instead of ImageServer in the URL to the image as well, and get nothing. I have tried replacing my dynamically built image URL with the exact URL of it going to that image in my documents and still get nothing).


So it turns out this was solely because I was trying to use SVG images. They, of course, uploaded to my documents just fine, and I assumed since they were coming from an authenticated source (Salesforce), it would be fine. But email clients seem to just want to cleanse svg attachments...

Switching them over to png's had them load just fine. But that is unfortunate because it would have been nice if I could let people upload SVG images as well...

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.