How do you embed images with Node.js mailgun. From reading the documentation, they use
-F inline=@files/cartman.jpg
The problem though, its for a curl example.
Here's what I have so far
Mailgun.sendHtmlEmail({
apiKey: '..',
domain: '...',
toEmail: created.email,
toName: created.email,
subject: 'mySite update',
htmlMessage: '<html><img style="display:block;" class="img1" src="cid:test.png" width="600" height="64" /></html>',
inline: 'email1/test.png',
fromEmail: '[email protected]',
fromName: 'Admin'
}).exec({
// An unexpected error occurred.
error: function (err){
console.log(err);
},
// OK.
success: function (){
}
});
When this was tested, there was no image attached.
I'm assuming you have to access the inline file for the email in a way Node.js can understand.
If so how do you do that?
Can someone point me in the right direction, please.
I would suggest you to use mailcomposer module to generate email message with attachments.
mailcomposer = new MailComposer({forceEmbeddedImages: true});
mailcomposer.addAttachment({
fileName: 'image.png',
filePath: IMAGES_PATH + '/image.png',
cid: '0o1q9i2w8u38ur.image.png'
});
mailcomposer.setMessageOption({
to: created.email,
from: '[email protected]',
subject: 'mySite update',
body: '...',
html: '<html>...</html>'
});
And you can send it through mailgun:
mailcomposer.buildMessage(function (err, message) {
if (err) {
// ...
}
mailgun
.messages()
.sendMime({
to: created.email,
message: message
}, function (err, response) {
// ...
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With