Reputation: 2913
I'am a newbie of Nodejs world. I want to send an email with embedded image. But my image didn't show in email. I thought it might be about my file path setting. Here is my mailOptions,
var mailOptions = {
from: '[email protected]',
to: to,
subject: subject,
html: html,
attachments: [{
filename: "logo.png",
filePath: "/images/logo.png",
cid: "logo-mail"
}]
};
And my directory that keeps my static files is
myproject/
assets/
images/
js/
styles/
And this is my html,
<img src="cid:logo-mail" />
Here is my result in an email,
<img src="cid.php?mid=e_ZGHjAQV4ZQLlAGNkZQNjZGN1AQt3Zt==&pj=logo-mail" alt="cid.php?mid=e_ZGHjAQV4ZQLlAGNkZQNjZGN1AQ">
I am not sure that am I right to set file path like this ?
filePath: "/images/logo.png"
Upvotes: 4
Views: 3899
Reputation: 2913
I did like this
filePath: process.cwd() + "/assets/images/logo.png"
And now it's working !
Thanks everyone for helping.
Upvotes: 3
Reputation: 5704
You need full path to your image
http://www.example.com/images/logo.png
since i could read your email on gmail.com the relative path would be translated to
gmail.com/images/logo.png
Upvotes: 1