Oll*_*lie 4 sendmail node.js handlebars.js
我刚刚继承了一个代码库,它使用把手作为电子邮件模板语言。
我已经四处搜寻以获取更多信息,但是找不到其他人这样做。
我只是想知道是否有人可以向我提供一些文档或搜索词来寻找。我不知道您甚至可以使用这样的把手!
谢谢,
奥利
电子邮件发件人
// 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) => {
...
});
})); }
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
小智 5
要执行基于文件.hbs作为模板发送的电子邮件,必须使用NPM软件包进行安装:
将设置主机信息:
var transport = nodemailer.createTransport({
host: 'YOUR HOST',
port: 'YOUR PORT',
auth: {
user: 'YOUR USER',
pass: 'YOUR PASSWORD'
},
tls: {
rejectUnauthorized: false
}
});
Run Code Online (Sandbox Code Playgroud)
现在,我们需要配置传输方式使其能够使用模板:
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' });
}
})
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3800 次 |
| 最近记录: |