Created
December 3, 2018 19:26
-
-
Save paivaric/ac46f5d35634ce7c26ef97f2260e6369 to your computer and use it in GitHub Desktop.
Mailgun request call
This file contains hidden or 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/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 = '[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) { | |
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