I know this issue is out there and I went through most of the "image not being displayed in email" questions, but nothing is helping me so far.
I am sending some images in my email.
In my controller I am generating the image url like this:
URL.getSalesforceBaseUrl().toExternalForm()+'/servlet/servlet.FileDownload?file='+imageId
These images are associated to the object record using Attachments.
The URL comes in properly in the email but the image is not shown. When I copied the url from the email and put it into another tab, it went to Salesforce login screen instead of showing the image.
I even tried to change the url to this:
URL.getSalesforceBaseUrl().toExternalForm()+'/servlet/servlet.ImageServer?id='+imageId+'&oid='+UserInfo.getOrganizationId()
But it still does not show my image. When I copy that url in a new tab and hit enter it gives me following error:
Unable to Access Page The value of the "id" parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit.
So I removed the last 3 characters of both ids to make them of length 15 but it still did not worked.
Am I doing something wrong. Any help and suggestions would be appreciated.