![](/img/trans.png)
[英]Sending a template to multiple people without knowing their email in sendgrid
[英]Sending an email template on request?
如何选择发送 email 的模板?
例如,我收到一个请求: reset_password
。 但我也有注册( signup
)。
我如何根据要求发送我需要的信件?
我想http://localhost:3000/sendmail?apiKey=test&type=reset_password
重置密码: http://localhost:3000/sendmail?apiKey=test&type=reset_password
注册: http://localhost:3000/sendmail?apiKey=test&type=signup
如果是注册,注册或密码重置信
我该如何处理? 请求发送您需要的模板
const transporter = require("./transporter");
const ejs = require('ejs')
const path = require('path')
const mailer = async (type, to) => {
what handler?
const reset_password = path.join(__dirname, "../reset_password.ejs"),
const signup = path.join(__dirname, "../signup.ejs")
const data = await ejs.renderFile(reset_password,signup { to });
const mainOptions = {
from: 'test',
to: to,
text: "Hello world?",
subject: 'dw',
html: data
};
return transporter.sendMail(mainOptions)
};
module.exports = mailer;
我该如何做到这一点:如果出现“reset_password”请求,则发送具有不同 email 模板的 email,如果是“注册”,则发送具有不同模板的 email。 在类型请求中出现 reset_password 或注册我不明白如何制作它,以便每个请求都有不同的 email 模板 ps:不同的类型。 和不同的字母模板
首先 - 修复您的邮件代码
const mailer = async (type, to) => {
const template = path.join(__dirname, `../${type}.ejs`)
const data = await ejs.renderFile(template, { to });
const mainOptions = {
from: 'test',
to: to,
text: "Hello world?",
subject: 'dw',
html: data
};
return transporter.sendMail(mainOptions)
};
然后,确保将类型参数(第一个)发送到邮件 function
const { apiKey, type } = req.query
const email = '...' // todo: grab user email
mailer(type, email)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.