Error: ENOENT: no such file or directory
Joeyrodrigues92 opened this issue · 3 comments
My handlebars file that i want to use in my email is able to be detected by nodmailer-express-handlebars. I may have my hbs object set up incorrectly. Any help is much appreciated .
MY DIR SET UP:
-emailViews
- index.handlebars
-layouts
-main.handlebars
`let transporter = nodemailer.createTransport( nodeMailgun(auth) );
transporter.use('compile', hbs({
viewEngine: {
extname: '.handlebars',
layoutsDir: 'emailViews/layouts',
defaultLayout: 'main',
partialsDir: 'emailViews/',
},
viewPath: './emailViews/layouts',
extName: '.handlebars'
})
);
// // send mail with defined transport object
let info = {
from: 'Excited User me@samples.mailgun.org', // sender address
to: "joeyrodrigues92@gmail.com", // list of receivers
subject: 'Nodemailer - Test',
text: 'Wooohooo it works!!',
context: {
userObjArr: userObjArr
}
// send extra values to template
};
transporter.sendMail(info, function(error, info){
if (error){
console.log('ERROR', error)
}else{
console.log('SENT', info)
}
})`
ERROR MESSAGE BELOW
ERROR [Error: ENOENT: no such file or directory, open '/Users/joeyrodrigues/Desktop/Open-List/open-list/emailViews/layouts/undefined.handlebars'] {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/Users/joeyrodrigues/Desktop/Open-List/open-list/emailViews/layouts/undefined.handlebars'
}
Hi Joey,
I guess index.handlebars is a template, and main.handlebars is the layout for all templates, correct?
In your info-object, you should add the template name you wish to use:
let info = {
from: 'Excited User me@samples.mailgun.org', // sender address
to: "joeyrodrigues92@gmail.com", // list of receivers
subject: 'Nodemailer - Test',
text: 'Wooohooo it works!!',
template: 'index',
context: {
userObjArr
}
};
This: viewPath: './emailViews/layouts',
should be: viewPath: 'emailViews'
instead.
Also note that you don't need to write extName: '.handlebars'
because .handlebars is already the default.
@AdamTorma Got it up and running thanks.
Thanks @AdamTorma.