这是我第一次使用 sendgrid 发送邮件。我对从数据库传递的动态数据有疑问。实际上,HTML 内容在对象中传递并在邮件中显示。有关更多详细信息,请查看以下对象。
{
to: "to Email"
from: "from email",
templateId: "Template ID",
dynamicTemplateData: {
subject: "Testing Templates",
name: "Some One",
city: "Denver",
week: "August 24 2020",
job0: {
header: "Test",
body: "<table border="0" cellspacing="0" cellpadding="0"> <tbody> <tr> <td class="
snip ">We are looking for physically fit individuals to fill general labour requirements by partnering with a truck driver. Your help is needed to load/unload the truck at the various job sites. <b>Skills required: </b> - comfortable with physical exertion and lifting minimum of 50lbs - works well on a team but trusted to work independently - reliable, self-motivated and committed to high standards of quality - able to read and understand work instructions <b>Specific requirements: </b> - in good physical condition - must have own safety footwear - reliable transportation to ensure punctual and consistent attendance If you meet the qualifications listed above, submit your resume in MS Word format via the link below. <i>Previously employed with The Staffing Connection? Please contact our office to confirm your continued availability for these upcoming positions.</i></td> </tr> </tbody> </table>",
cta: "Apply now",
url: "My URL"
},
}
}
代码
getJobs().then((jobs) => {
var mailPayload = {
to: emails,
from: "",
templateId: "",
dynamicTemplateData: {
subject: "Testing Templates",
name: "Some One",
city: "Denver",
week: "August 24 2020",
},
};
for (let i = 0; i < jobs.length; i++) {
mailPayload.dynamicTemplateData["job" + i] = {
header: jobs[i].job_title,
body: jobs[i].job_description,
cta: "Apply now",
url: jobs[i].company_url,
};
}
mail(mailPayload);
res.send("Mail sent Successfully").status(200);
});
});
这是输出
请帮我解决这个问题。