Skip to content

Instantly share code, notes, and snippets.

@nam178
Last active January 19, 2016 00:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nam178/26de4b29dcac9d1334c8 to your computer and use it in GitHub Desktop.
Save nam178/26de4b29dcac9d1334c8 to your computer and use it in GitHub Desktop.
Demonstration on how to send email with AWS Lambda + SES
var myPersonalEmailAddress = 'nam@catapultsports.com';
var aws = require('aws-sdk');
var ses = new aws.SES({apiVersion: '2010-12-01'});
exports.handler = function(event, context) {
if (false == !!event.ClientName)
{
context.fail('Missing clientName');
return;
}
if (false == !!event.ClientEmail)
{
context.fail ('Missing clientEmail');
return;
}
if (false == !!event.ClientMessage)
{
context.fail ('Missing clientMessage');
return;
}
var params = {
Destination: {
BccAddresses:[],
CcAddresses: [],
ToAddresses: [myPersonalEmailAddress]
},
Message: {
Body: {
Text: {
Data: event.ClientMessage,
Charset: 'UTF-8'
}
},
Subject: {
Data: 'Mesage from ' + event.ClientName + " (" + event.ClientEmail + ")",
Charset: 'UTF-8'
}
},
Source: myPersonalEmailAddress,
ReplyToAddresses: [event.ClientEmail]
};
ses.sendEmail(params, function(err, data) {
if (err) {
console.log(err, err.stack);
context.fail ('mailer error');
} else {
console.log(data); // successful response
context.succeed('ok');
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment