在AWS Lambda函数中设置与“发件人”地址不同的“回复”邮件地址(node.js)

omqzjyyz  于 12个月前  发布在  Node.js
关注(0)|答案(1)|浏览(119)

我有一个html联系表单,其中的提交由Node.js编写的AWS Lambda函数处理,该函数将提交格式化为电子邮件,然后通过AWS SES发送。
正如您在下面的代码中所看到的,邮件是通过AWS SES批准的固定邮件地址发送的。我想添加一个“reply-to”属性,以便当我收到邮件并单击回复时,我不会回复“email protected(https://stackoverflow.com/cdn-cgi/l/email-protection)“,而是回复到该人在html表单中提交的电子邮件地址:“senderEmail”
据我所知,这是可能的,但我找不到正确的语法使它工作.因为知道它被注解掉,因为否则它会制动我的功能。任何帮助都非常感谢!

const aws = require("aws-sdk");
const ses = new aws.SES({ region: "eu-central-1" });
exports.handler = async function(event) {
  // Extract the properties from the event body
  const { senderEmail, senderName, messageSubject, message } = JSON.parse(event.body)
  const params = {
    Destination: {
      ToAddresses: ["[email protected]"],
    },
    // Interpolate the data in the strings to send
    Message: {
      Body: {
        Text: {
          Data: `Nom : ${senderName}
          Adresse mail : ${senderEmail}
          Sujet : ${messageSubject}
          Message : ${message}`
        },
      },
      Subject: { Data: `${messageSubject} (${senderName})` },
    },
    Source: "[email protected]",
    // Set a reply-to adress that is different from the "source:" and allows to respond directly to the person submitting the form
    // ReplyTo: { Data: `${senderEmail}`},
  };

  return ses.sendEmail(params).promise();
};

字符串
我尝试了不同的语法,但都不起作用,因为我是新手,我不知道在哪里可以找到正确的语法(同样是node.js 14.x)。

mmvthczy

mmvthczy1#

根据这里的文档,它应该是ReplyToAddresses。ReplyToString将电子邮件数组作为值。

const aws = require("aws-sdk");
const ses = new aws.SES({ region: "eu-central-1" });
exports.handler = async function(event) {
  // Extract the properties from the event body
  const { senderEmail, senderName, messageSubject, message } = JSON.parse(event.body)
  const params = {
    Destination: {
      ToAddresses: ["[email protected]"],
    },
    // Interpolate the data in the strings to send
    Message: {
      Body: {
        Text: {
          Data: `Nom : ${senderName}
          Adresse mail : ${senderEmail}
          Sujet : ${messageSubject}
          Message : ${message}`
        },
      },
      Subject: { Data: `${messageSubject} (${senderName})` },
    },
    Source: "[email protected]",
    // Set a reply-to adress that is different from the "source:" and allows to respond directly to the person submitting the form
    ReplyToAddresses: [senderEmail],
  };

  return ses.sendEmail(params).promise();
};

字符串

相关问题