【问题标题】:Is there a way of dynamically changing the email template subject field on SES templates?有没有办法动态更改 SES 模板上的电子邮件模板主题字段?
【发布时间】:2019-12-27 14:02:09
【问题描述】:

我目前正在使用 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”更改为“Other Title”?

【问题讨论】:

    标签: node.js amazon-web-services amazon-ses email-templates


    【解决方案1】:

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

    templateSubject: "Important Message for {{ 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 中阅读有关 sendTemplatedEmail 属性的更多信息,以及创建和自定义 SES 电子邮件模板 here

    【讨论】:

    • 正是我需要的。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-21
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 2015-08-25
    • 2022-01-20
    • 1970-01-01
    相关资源
    最近更新 更多