[SalesForce] Why won’t HTML formatted mails show correct in Salesforce on a case (Email-to-Case functionality)

I have enabled Email-to-Case functionality and in Email-to-Case settings checked:
Enable Email-to-Case
Enable HTML Email
Enable on-demand service
And routing adress is also set up.

Salesforce creates a case on behalf of the received email and does this fine.
The problem is when the email has an attachment, then the email doesn't show as I would like it to:
Email-converted to case

Below is how an email shows in salesforce (inbound email message) when i click "click here to view HTML version" link:

HTML version of email

I want the pictures to be shown is that possible?

Im aware that they are showing below as attachments, but want them to be shown either in the normal view of the case or in the "HTML version" view.

Is it possible to link to the html version of the email from the case description?
And of course show the pictures in the html version also?

I will try to solve the problem with standard functionality if possible.
Thanks in advance 🙂

Best Answer

Update: Summer15 now supports images in emails. However it only works currently in case feed and in the "click here to view HTML version" link on the email record.


Your issue isn't with the HTML of the email, it is the embedded images. It is a long known 'limitation' of salesforce.

https://success.salesforce.com/ideaView?id=08730000000Gp9dAAC

If you need a hacky workaround, the image place holders in the email message body can be matched to image attachments based on an Id order.

Expanded explanation: (please don't do this)

The place holders come in two forms

  • cid:imageName.png@asdf
  • cid:asdf

If the placeholder is in the first form, then you can just match the attachment by name. If it is in the 2nd form, the place older position is the same as the order the image attachment was inserted

List<Attachment> attachments = [
    SELECT Id
        , Body
        , ContentType
        , Name 
    FROM Attachment
    WHERE ParentId = :email.Id
    and contentType like 'image/%'
    order by Id asc];

Map<String, Attachment> attachmentMap = new Map<String, Attachment>();
for (Attachment a : attachments){
    attachmentMap.put(a.Name, a);
}

//list all the content-ids (cids) in the email
List<String> cidList = ....
for (Integer i = 0; i < cidList.size() && i < attachments.size(); i++){
    String cid = cidList[i];
    if (cid is of first form){
        .... get attachment by name
        Attachment a = attachmentMap.get(imageName);
    } else {
        .... cid is of 2nd form
        Attachment a = attachments[i];
    }

}