Created
October 31, 2015 10:48
-
-
Save neguse11/9d3e27ee294436102758 to your computer and use it in GitHub Desktop.
Call Mailgun API from node.js with Request
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
// node.js : Mailgun via API | |
var request = require('request') | |
var apiBaseUrl = 'https://api.mailgun.net/v3/sandboxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.mailgun.org'; | |
var apiKey = 'key-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; | |
var from = 'Excited User'; | |
var to = '[email protected]'; | |
var subject = 'Hello'; | |
var text = 'Testing some Mailgun awesomness!'; | |
var mailgunOpts = { | |
url: apiBaseUrl + '/messages', | |
headers: { | |
Authorization: 'Basic ' + new Buffer('api:' + apiKey).toString('base64') | |
}, | |
form: { | |
from : from, | |
to : to, | |
subject: subject, | |
text : text | |
} | |
}; | |
request.post(mailgunOpts, function(err, response, body) { | |
console.log(err || body); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment