Skip to content

Instantly share code, notes, and snippets.

@neguse11
Created October 31, 2015 10:48
Show Gist options
  • Save neguse11/9d3e27ee294436102758 to your computer and use it in GitHub Desktop.
Save neguse11/9d3e27ee294436102758 to your computer and use it in GitHub Desktop.
Call Mailgun API from node.js with Request
// 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 = 'example@example.com';
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