gpt4 book ai didi

node.js - 使用 Express-mailer 将本地值传递给电子邮件模板

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

我想在用户注册后发送一封感谢邮件,但我不知道如何将用户名传递到我的电子邮件模板。我有以下代码:

app.mailer.send('email', {
to: 'newuser@gmail.com', // REQUIRED. This can be a comma delimited string just like a normal email to field.
subject: 'Test Email', // REQUIRED.
user: req.body.user, // All additional properties are also passed to the template as local variables.
}, function (err) {
if (err) {
// handle error
console.log(err);
res.send('There was an error sending the email');
return;
}
res.send('Email Sent');
});

电子邮件模板:

<html>
<head>
<title>{{subject}}</title>
</head>
<body>
Thank you {{user}}
</body>
</html>

最佳答案

您可以将属性传递给请求。

{
至:'newuser@gmail.com',//必需。这可以是逗号分隔的字符串,就像普通的电子邮件收件人字段一样。
主题:'测试电子邮件',//必需。
用户名:req.body.username,
myVar: '用户名'
}

变量 myVar 作为局部变量传递给模板

关于node.js - 使用 Express-mailer 将本地值传递给电子邮件模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32679161/

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