有没有办法动态更改 SES 模板上的电子邮件模板主题字段?

Is there a way of dynamically changing the email template subject field on SES templates?

我目前正在使用 SES 在部署时使用 serverless-ses-template 存储电子邮件模板。
模板使用以下参数存储,这两个参数都是必需的:

templateId: 'status-template',
templateSubject: 'Some Title'

在我的 Lambda 中,我得到了我需要的模板,我将值映射到模板并发送它:

const email = {
        Destination: {
            ToAddresses: targetAddresses
        },
        Source: 'sourcemail@mail.com',
        Template: "status-template",
        TemplateData: JSON.stringify(templateData)
    };

await ses.sendTemplatedEmail(email).promise();

收到这封电子邮件后,主题应与模板中的一样 "Some Title"。
有没有办法在发送之前动态更改该标题,即将标题从 "Some Title" 更改为 "Other Title"?

您可以自定义您的主题和几乎任何其他字段,方法是创建本质上是自定义字段值并将其括在双花括号中,如下所示:

templateSubject: "Important Message for {{ username }}"

然后将您的 "username" 参数添加到您的 templateData 对象,当发送电子邮件时,它会将 {{ username }} 替换为值,在本例中为 "Marko Nikolov" .

const templateData = {
    "username": "Marko Nikolov"
};

const email = {
        Destination: {
            ToAddresses: targetAddresses
        },
        Source: 'sourcemail@mail.com',
        Template: "status-template",
        TemplateData: JSON.stringify(templateData),
    };

await ses.sendTemplatedEmail(email).promise();

您可以在 API 文档 here, and creating and customizing SES email templates here 中阅读有关 sendTemplatedEmail 属性 的更多信息。