yads/nodemailer-express-handlebars

you can not render a difeerent template when define defaultLayout

yjarid opened this issue · 2 comments

i have a simple set up , so I define the defaultLayout to be 'resetPassword' and I exported the mailOptions alowing me to customize its parameters, so this setup is working fine at the exception of the template parameters, even when I change it the email is always sent with the defaultLayout template.

PS: I manged to workaroud this issue by setting the defaultLayout to false , but I am hoping there is a better solution

import nodemailer from 'nodemailer'
import hbs from 'nodemailer-express-handlebars'


export const transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
        user: process.env.EMAIL,
        pass: process.env.PASS
    }
})



transporter.use('compile', hbs({
    viewEngine: {
        extName: '.handlebars',
        partialsDir:  "mail/views",
        layoutsDir:  "mail/views",
        defaultLayout: 'resetPassword',
    },
    viewPath: 'mail/views/',
    extName: '.handlebars'
}))

export const mailOptions = (to, template , subject, context) => ({
    from : 'myemail@gamil.com',
    to,
    subject,
    template ,
    context 
})


+1
I have the same problem and had to set defaultLayout to false

+1 I have the same problem and had to set defaultLayout to false

Thank you, Your solution was working.