我有一个 html 联系表单,其中提交内容由用 Node.js 编写的 AWS Lambda 函数处理,该函数将提交内容格式化为电子邮件,然后通过 AWS SES 发送。
正如您在下面的代码中看到的,邮件是通过 AWS SES 批准的固定邮件地址发送的。我想添加一个“reply-to”属性,这样当我收到邮件并点击回复时,我不会回复“[email protected]”,而是回复到该人在html表单中提交的电子邮件地址: “发件人邮箱”
据我所知,这是可能的,但我找不到正确的语法来使其工作......因为知道它被注释掉了,因为否则它会阻止我的功能。非常感谢任何帮助!
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)。
根据文档here,它应该是
ReplyToAddresses
。 ReplyToAddresses 将电子邮件数组作为值。
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();
};