yads / nodemailer-express-handlebars

A plugin for nodemailer that uses express-handlebars view engine to generate emails
87 stars 30 forks source link

Expecting main.handlebars - error- ENOENT: no such file or directory, open \main.handlebars #41

Closed Tech-AJ closed 4 years ago

Tech-AJ commented 4 years ago

I am using the following code-

var handlebarsOptions = {
    viewEngine: 'handlebars',
    extName: '.html',
    viewPath: path.resolve('./api/templates/'),

};

smtpTransport.use('compile', hbs(handlebarsOptions));

var data = {
                to: user.email,
                from: email,
                template: 'forgot_password',
                subject: 'Password help has arrived!',
                context: {
                    url: 'http://localhost:3000/auth/reset_password?token=' + token,
                    name: user.fullName.split(' ')[0]
                }
            };

            smtpTransport.sendMail(data, function(err) {
                if (!err) {
                    console.log('Kindly check your email for further instructions' );
                    return res.json({ message: 'Kindly check your email for further instructions' });
                } else {
                    console.log("Send mail")
                    console.log(err);
                    return done(err);
                }
}

and my directory structure is image

I am getting the folllowing error - [Error: ENOENT: no such file or directory, open 'C:\Users\path\main.handlebars'] { errno: -4058, code: 'ENOENT', syscall: 'open', path: 'C:\Users\path\main.handlebars'

Why is it expecting main.handlebars and not working?

yads commented 4 years ago

See plugin options https://github.com/yads/nodemailer-express-handlebars#plugin-options. viewEngine must either be an instance of express-handlebars or an options hash to pass to express-handlebars. https://github.com/express-handlebars/express-handlebars#configuration-and-defaults