Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
127
rated 0 times [  129] [ 2]  / answers: 1 / hits: 48296  / 6 Years ago, thu, january 25, 2018, 12:00:00

I am following the approach used in the nodemailer community site
but I cannot seem to get it to work as I am getting the error



   Failed to send email { Error: ENOENT: no such file or directory, open 
'./rello-logo-full-svg.svg'
errno: -2,
code: 'ESTREAM',
syscall: 'open',
path: './rello-logo-full-svg.svg',
command: 'API' }


The nodemailer options are as follows



    let mailOptions = {
from: '<from_email>',
to: to_email_address.toString(),
subject: 'Subject',
text: 'Hello world', // plain text body
attachments: [{
filename: 'rello-logo-full-svg.svg',
path: './rello-logo-full-svg.svg',
cid: 'unique@cid'
}],
html: emailBody
};


And in the emailBody variable I have a template string with an image tag line like so



<img style=width:250px; cid:unique@cid>


Do I maybe need to set the static assets for express or what, the image file is in the same folder as the file that has the above code, any help is appreciated


More From » node.js

 Answers
11

So I got it to work by using
...



 path: __dirname + '/rello-logo-full-svg.svg',


....



But funny this is not what I was trying to achieve because I wanted the image to be in the email body, bu hope this'll help someone else.



Hey, I just changed the file name from .svg to .png, another mistake I made was with the image in the template, I have changed it to



 <img style=width:250px; src=cid:unique@cid>

[#55358] Tuesday, January 23, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaceyr

Total Points: 510
Total Questions: 97
Total Answers: 116

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
kaceyr questions
;