Skip to content

Instantly share code, notes, and snippets.

@mshuber1981
Last active June 24, 2022 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mshuber1981/591573070957a6102770ce99dec2f936 to your computer and use it in GitHub Desktop.
Save mshuber1981/591573070957a6102770ce99dec2f936 to your computer and use it in GitHub Desktop.
AWS Contact Form Lambda (Node.js) with SES example
// Full example - https://aws.amazon.com/blogs/architecture/create-dynamic-contact-forms-for-s3-static-websites-using-aws-lambda-amazon-api-gateway-and-amazon-ses/
const AWS = require('aws-sdk');
const ses = new AWS.SES();
// https://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-email-addresses.html
const SENDER = 'Your verified SES email address';
function sendEmail (event) {
let params = {
Destination: {
ToAddresses: [
SENDER
]
},
Message: {
Body: {
Text: {
Data: 'Name: ' + event.name + '\nEmail: ' + event.email + '\nMessage: ' + event.message,
Charset: 'UTF-8'
}
},
Subject: {
Data: 'Contact Form: ' + event.name,
Charset: 'UTF-8'
}
},
Source: SENDER
}
ses.sendEmail(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log(data);
});
};
exports.handler = function (event) {
console.log('Received event:', event);
sendEmail(event);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment