Hi, I know this issue has been closed but this is more a problem I have been having when trying to send embedded images to a gmail user.
I found a couple of reasons to why gmail would not render images due to some additional security they impose so I thought I would use the attachments parameter to add a content_id and see if that works instead of using a regular src tag with a link.
When it is sent send grid returns a bad request. Here is my method.
I encode the JPG like so:
let bitmap = fs.readFileSync(imageDir);
imageBase64URL = new Buffer(bitmap).toString('base64');
Then I pass in the encoded JPG into the content field inside the attachments argument:
mailer.send({
to: '[email protected]',
from: '[email protected]',
subject: `You have been removed from ${house.name} by ${removerName}`,
html: result,
attachments: [
{
content: imageBase64URL,
filename: 'cluttr-logo.jpg',
contentId: 'cluttr-logo'
},
]
});
Finally I embed my CID like so into my ejs file:
<img alt="Logo" src="cid:cluttr-logo" width="60"
height="60"
Hopefully someone has some insight to what I am doing wrong. Thanks.
//imageData= "data:image/png;base64,ine793nfdsf......."
imageb64 = imageData.replace('data:image/png;base64,' , '');
//remove data:image/png;base64,
const msg = {
to: '[email protected]',
from: '[email protected]',
subject: "image attached",
html :'<img src="cid:myimagecid"/>',
attachments: [
{
filename: "imageattachment.png",
content: imageb64,
content_id: "myimagecid",
}
]
};
sgMail.send(msg);
Hello @lvh1g15,
Were you able to resolve the issue?
I have the same problem in gmail... any solutions?
@huggler Please open a new issue.