Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (52 sloc) 1.83 KB
exports.handler = function(event, context, callback) {
var AWS = require('aws-sdk');
AWS.config.region = 'us-west-2';
var SES = new AWS.SES();
var obj = JSON.parse(event.body);
var to = (obj.to === undefined ? 'Undefined (to)' : obj.to);
var body = (obj.body === undefined ? 'Undefined (body)' : obj.body);
var from = (obj.from === undefined ? 'Undefined (from)' : obj.from);
var id = (obj.id === undefined ? 'Undefined (id)' : obj.id);
var emailParams = {
Destination: {
ToAddresses: ["recipient@edge-cloud.net"]
},
Message: {
Body: {
Html: {
Data: "From: " + from + "<br>To: " + to + "<br>Message: " + body + "<p>ID: " + id
},
Text: {
Data: "From: " + from + "\nTo: " + to + "\nMessage: " + body + "\n\n" + id
}
},
Subject: {
Data: "Text message to " + to
}
},
Source: from + "<sms@edge-cloud.net>"
};
var email = SES.sendEmail(emailParams, function(err, data){
if(err) {
var responseBody = {
message: "Message failed"
};
var response = {
statusCode: '500',
body: JSON.stringify(responseBody)
};
console.log("response: " + JSON.stringify(response))
context.succeed(response);
} else {
var responseBody = {
message: "Message suceeded"
};
var response = {
statusCode: '200',
body: JSON.stringify(responseBody)
};
console.log("response: " + JSON.stringify(response))
context.succeed(response);
}
});
};