Skip to content

Instantly share code, notes, and snippets.

@WendySanarwanto
Created August 14, 2017 09:50
Show Gist options
  • Save WendySanarwanto/8022dce3cadc3eff651f5f1db4d7ad82 to your computer and use it in GitHub Desktop.
Save WendySanarwanto/8022dce3cadc3eff651f5f1db4d7ad82 to your computer and use it in GitHub Desktop.
A code sample of sending email from AWS SES.
'use strict';
const aws = require('aws-sdk');
exports.handler = (event, context, callback) => {
const homeRegion = "us-east-1";
const accessKeyId = "YOURACCESSKEYID";
const secretAccessKey = "YOURSECRETACCESKEY";
// load AWS SES
const ses_config = {
apiVersion: "2010-12-01",
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
region: homeRegion
};
const ses = new aws.SES(ses_config);
const recipient = ["saintc0d3r@gmail.com"];
const sender = "wendy.sanarwanto@gmail.com";
// do send email
const send_email_params = {
Source: sender,
Destination: {
ToAddresses: recipient
},
Message: {
Subject: {
Data: '[AWS] Test Send Email from AWS SES'
},
Body: {
Text: {
Data: 'This is a test message sent from AWS SES.'
}
}
}
};
ses.sendEmail(send_email_params, (err, data) => {
if(err) {
callback(err);
}
callback(null, 'Email has been sent');
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment