Created
August 14, 2017 09:50
-
-
Save WendySanarwanto/8022dce3cadc3eff651f5f1db4d7ad82 to your computer and use it in GitHub Desktop.
A code sample of sending email from AWS SES.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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