Reputation: 1032
I want to add image to email. I tried several ways the final solution I am having is to add image as linkedResource but it will increase the size of email and I don't want that as email is already having several attachments.I am using xslt file to get html body of email from XML input. I am adding the image as following
<img src="http://placehold.it/350x150">
but somehow the image is shown as red cross in outlook client in microsoft office and in .mht file.Emails look fine in outlook webmail client and on different browsers.
If I see the network tab in browser after I open the mail in browser from outlook client in microsoft office the request can be seen for url 'http://placehold.it/350x150' but received bytes are zero and response is blank.
Is there any way to add image to email without using linkedResource? Your help will be really great to me.
Upvotes: 1
Views: 1399
Reputation: 4749
Encode the image using base64 and add like this:
<img src="data:image/JPEG;base64,{encoded string}">
Where the {encoded string} part is a base64 encoding of image data. JPEG can be gif or whatever according to type of image.
Upvotes: 1
Reputation: 428
You could use embedded images.
<img alt="My Image" src="data:image/jpeg;base64,/9j/4S/+RXhpZgAATU0AKgAAAAgACAESAAMAENkDZ5u8/61a+X...more encoding" />
More info here: https://sendgrid.com/blog/embedding-images-emails-facts/
PS. A while ago we have an problem with email rendering in different browsers and email clients. And storing images as described was the best solution (for images, ofc :)).
Upvotes: 0