0

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?

1
  • add your nodejs code Commented Sep 30, 2019 at 8:38

2 Answers 2

2

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
    }]
}

source

if this is not working there could be problem in your image path try using path: __dirname +'/path/to/file/image.png',

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Krishna. I'm not using nodemailer or any other node service to send mail. It a different SOAP service created locally.
1

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">

1 Comment

Thanks for the answer but I have to send images in base64 format only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.