yads / nodemailer-express-handlebars

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

Handlebars: Access has been denied to resolve the property "author" because it is not an "own property" of its parent. You can add a runtime option to disable the check or this warning: See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details #35

Closed Wennlys closed 4 years ago

Wennlys commented 4 years ago

I've already to read Handlebars's documentation and topic about this problem but I didn't find anything related with nodemailer-express-handlebars


**Mail.js** = const path = require('path')
const nodemailer = require('nodemailer')
const handlebars = require('express-handlebars')
const hbs = require('nodemailer-express-handlebars')

const mailConfig = require('../../config/mail')

const transport = nodemailer.createTransport(mailConfig)

const viewPath = path.resolve(__dirname, '..', 'views', 'mails')

transport.use(
  'compile',
  hbs({
    viewEngine: handlebars.create({
      partialsDir: path.resolve(viewPath, 'partials')
    }),
    viewPath,
    extName: '.hbs'
  })
)

module.exports = transport

----------------------------------------------------------------------------------------------------------------
**PurchaseControlelr that uses 'Main.js'** = `class PurchaseController {
  async store(req, res) {
    const { ad, content } = req.body

    const purchaseAd = await Ad.findById(ad).populate('author')
    const user = await User.findById(req.userId)

    await Mail.sendMail({
      from: '"Wennlys Oliveira" <wennlys@gmail.com>',
      to: purchaseAd.author.email,
      subject: `Purchase solicitation: ${purchaseAd.title}`,
      template: 'purchase',
      context: { user, content, ad: purchaseAd }
    })

    return res.send()
  }
}
yads commented 4 years ago

This seems to be an issue with handlebars itself.