Я отправляю шаблонное письмо, используя nodemailer
с nodemailer-express-handlebars
, но всякий раз, когда я пытаюсь отправить письмо, я получаю
Error: A partials dir must be a string or config object.
Я не получаюзнаю в чем проблема.
const express = require('express');
const hbs = require('nodemailer-express-handlebars');
const nodemailer = require('nodemailer');
const app = express();
const user_name = 'xxxxxxxxxxx@gmail.com';
const refresh_token = 'xxxxxxxxxxxxxxxxxxxxxxxx';
const client_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
const client_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
const email_to = 'yyyyyyyyyyyyyyyyyy@gmail.com';
let transporter = nodemailer
.createTransport({
service: 'Gmail',
auth: {
type: 'OAuth2',
clientId: client_id,
clientSecret: client_secret
},
tls:{
rejectUnauthorized: false
}
});
transporter.use('compile', hbs({
viewPath: 'views/email',
extName: '.hbs'
}));
transporter.on('token', token => {
console.log('A new access token was generated');
console.log('User: %s', token.user);
console.log('Access Token: %s', token.accessToken);
console.log('Expires: %s', new Date(token.expires));
});
let mailOptions = {
from : user_name,
to : email_to,
subject : 'Hello ✔',
text : 'Hello world ?',
template: 'emailt',
context: {},
auth : {
user : user_name,
refreshToken : refresh_token,
expires : 1494388182480
}
};
// send mail with defined transport object
app.get('/', (req,res) => {
transporter.sendMail(mailOptions).then( r => {
res.send(r);
}).catch(e =>{
res.send(e);
});
});
app.listen(3000 ,()=>{
console.log('port: 3000');
});
Мой каталог выглядит так views>email>emailt.hbs