gpt4 book ai didi

node.js - Handlebars 作为电子邮件模板

转载 作者:搜寻专家 更新时间:2023-10-31 22:58:53 27 4
gpt4 key购买 nike

我刚刚继承了一个代码库,它使用 handlebars 作为电子邮件模板语言。

我四处搜索以尝试获取更多信息,但找不到其他人这样做。

我只是想知道是否有人可以提供一些文档或搜索词供我查找。我不知道您甚至可以使用这样的 Handlebars !

谢谢,

奥利


电子邮件发件人

// Send new account email 
function sendNewAccountEmail(expert) {
...
return handlebars.render('views/emails/newAccountEmail.handlebars', {
name: `${expert.firstName} ${expert.lastName}`,
layout: false,
expert,
url: `${LIVE_URL}/expert/reset/${expert.resetPasswordToken}`,
}).then(email => new Promise((resolve, reject) => {
sendmail({
from: SEND_EMAIL,
to: recipient,
subject: '',
text: email,
}, (err, reply) => {
...
});
})); }

newAccountEmail.handlebars

Hi {{name}},

You now have access to RARA Survey tool!
You can now access your dashboard and assigned campaigns by going to the following link and creating a password:

Login URL: {{url}}

Thanks!

Influencer Team

最佳答案

要实现基于文件.hbs 为模板发送的电子邮件,需要使用包的NPM 安装:

  1. Node 邮件
  2. nodemailer-express-handlebars

设置主机信息:

    var transport = nodemailer.createTransport({
host: 'YOUR HOST',
port: 'YOUR PORT',
auth: {
user: 'YOUR USER',
pass: 'YOUR PASSWORD'
},
tls: {
rejectUnauthorized: false
}
});

现在,我们需要配置传输以使其能够使用模板:

    transport.use('compile', hbs({    
viewPath: 'YOUR PATH where the files are, for example /app/view/email',
extName: '.hbs'
}));



exports.sendEmail = function (from, to, subject, callback) {

var email = {
from: 'YOUR FROM FOR EXAMPLE YOU@GMAIL.COM',
to: 'RECIPIENT',
subject: 'SUBJECT',
template: 'TEMPLATE NAME, DO NOT NEED TO PLACE .HBS',
context: {
name: 'YOUR NAME',
url: 'YOUR URL'
}
};

transport.sendMail(email, function (err) {
if (err) {
return callback({ 'status': 'error', 'erro': err });
}
else {
return callback({ 'status': 'success' });
}
})
};

关于node.js - Handlebars 作为电子邮件模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47141100/

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