yads / nodemailer-express-handlebars

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

you can not render a difeerent template when define defaultLayout #34

Open yjarid opened 4 years ago

yjarid commented 4 years ago

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 
})
tristanguerin commented 4 years ago

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

milad2golnia commented 10 months ago

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

Thank you, Your solution was working.