I have an html contact form where the submissions are processed by a AWS Lambda function written in Node.js that formats the submission into an email then sent via AWS SES.
As you can see in the code below, the mail is sent by a fixed mail address, approved by AWS SES. I want to add a "reply-to" attribute, so that when I receive the mail and click reply, I am not replying to "formsender@emailaddress.com", but to the email address the person submitted in the html form : "senderEmail"
As far as I know, it is possible, but I can't find the correct syntax to make it work... for know it is commented out because else it brakes my function. Any help is much appreciated !
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: ["my@emailaddress.com"],
},
// 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: "formsender@emailaddress.com",
// 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();
};
I tried different syntaxes, but none worked, and since I am fairly new to this I don't know where to find the correct syntax (again for node.js 14.x).
As per the doc here, it should be ReplyToAddresses
. ReplyToAddresses takes array of email as values.
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: ["my@emailaddress.com"],
},
// 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: "formsender@emailaddress.com",
// 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();
};