gpt4 book ai didi

node.js - 错误: A partials dir must be a string or config object in handlebars

转载 作者:行者123 更新时间:2023-12-02 15:09:59 27 4
gpt4 key购买 nike

我使用 nodemailernodemailer-express-handlebars 发送模板电子邮件,但每当我尝试发送邮件时,我都会收到

错误:部分目录必须是字符串或配置对象。

我不知道问题出在哪里。

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

最佳答案

看起来最近对express-handlebars的更改导致了这个问题,有人在这里发布了修复https://github.com/yads/nodemailer-express-handlebars/issues/22

或者

我想您可以返回到没有此问题的版本,至少在问题得到修复之前。

关于node.js - 错误: A partials dir must be a string or config object in handlebars,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55010504/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com