Skip to content

Instantly share code, notes, and snippets.

@grantstephens
Created January 31, 2019 11:40
Show Gist options
  • Save grantstephens/b39f2fce14269e6f152af15d9fa25ecd to your computer and use it in GitHub Desktop.
Save grantstephens/b39f2fce14269e6f152af15d9fa25ecd to your computer and use it in GitHub Desktop.
Twilio Function Script to forward text messages sent to a twilio number to email via the mandril api
const mandrill = require('mandrill-api')
mandrill_client = new mandrill.Mandrill('#key-here');
exports.handler = function(context, event, callback) {
const message = {
"text": event.Body,
"subject": `New SMS message from: ${event.From}`,
"from_email": "#from-address here",
"from_name": "#from-here",
"to": [{
"email": "#email-here",
"name": "To Here",
"type": "to"
}],
};
var async = false;
var ip_pool = "Main Pool";
mandrill_client.messages.send({"message": message, "async": async, "ip_pool": ip_pool}, function(result) {
console.log(result);
}, function(e) {
console.log('A mandrill error occurred: ' + e.name + ' - ' + e.message);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment