Skip to content

Instantly share code, notes, and snippets.

@paivaric
Created December 3, 2018 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paivaric/ac46f5d35634ce7c26ef97f2260e6369 to your computer and use it in GitHub Desktop.
Save paivaric/ac46f5d35634ce7c26ef97f2260e6369 to your computer and use it in GitHub Desktop.
Mailgun request call
// node.js : Mailgun via API
var request = require('request')
var apiBaseUrl = 'https://api.mailgun.net/v3/YOUR_DOMAIN_NAME'; // REPLACE THIS BY YOUR DOMAIN NAME
var apiKey = 'key-YOUR_API_KEY'; // REPLACE THIS BY YOUR API KEY
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) {
if (err) {
console.error(err);
process.exit(1);
} else {
console.log('email sent!');
process.exit(0);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment