Reputation: 1
I added an image in HTML template of email as below:
<table>
<tr>
<td>
<img src="data:image/png;base64,iVBORw0KGgoAA.........." width="30%" height="150">
</td>
</tr>
</table>
but in gmail the image is not rendering as src is skipped:
<img width="30%" height="150">
Any solution?
Upvotes: 0
Views: 2612
Reputation: 599
Adding to Krishna Sapkal's answer, if you want to reduce the space used up sending the whole mail with attachment(or even base64 data) you could upload the image to some place such as imgur.com or even an AWS S3 bucket and call it with the src.
<img src="https://i.sstatic.net/{image_name_goes_here}.jpg" width="30%" height="150">
Upvotes: 1
Reputation: 695
If you are using node mailer. Attachments can be used as embedded images in the HTML body. To use this feature, you need to set additional property of the attachment – cid (unique identifier of the file) which is a reference to the attachment file. The same cid value must be used as the image URL in HTML (using cid: as the URL protocol, see example below). Note : cid should be as unique as possible.
var mailOptions = {
...
html: 'Embedded image: <img src="cid:[email protected]"/>',
attachments: [{
filename: 'image.png',
path: '/path/to/file/image.png',
cid: '[email protected]' //same cid value as in the html img src
}]
}
if this is not working there could be problem in your image path try using
path: __dirname +'/path/to/file/image.png',
Upvotes: 2