yads / nodemailer-express-handlebars

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

Why is it looking for main.handlebars as template? #57

Closed jackli199311 closed 2 years ago

jackli199311 commented 2 years ago

I using Nest.js and I'm not sure if it's causing this issue. I have the following function: ` public async send(mailerDto: MailerDto) { const transporter = nodemailer.createTransport({ host: this.configService.get('EMAIL_HOST'), port: 465, secure: true, auth: { user: this.configService.get('EMAIL_USER'), pass: this.configService.get('EMAIL_PASSWORD'), }, tls: { rejectUnauthorized: false, minVersion: 'TLSv1.2', }, });

transporter.use(
  'compile',
  hbs({
    viewEngine: 'express-handlebars',
    viewPath: './templates',
  }),
);

const info = await transporter.sendMail({
  from: '"Security Passport" <securitypassport@sap.com>',
  to: mailerDto.recipients,
  subject: mailerDto.subject,
  text: mailerDto.text,
  html: mailerDto.html,
  template: 'password-rotation',
});

console.log('Message sent: %s', info.messageId);

}`

I'm getting ERROR [ExceptionsHandler] ENOENT: no such file or directory, open 'C:\work\passport\security-passport\apps\passport-mailer\main.handlebars'

After I added main.handlebars it works fine but I'm not able to use the templates I defined in other places. It's always using this main.handlebars.

What's with this main.handlebars?