Forked from neguse11/node-js-mailgun-via-api.js
Last active
December 3, 2018 19:14
-
-
Save paivaric/3ed7e2e07f95e54dd37fcc54d1136636 to your computer and use it in GitHub Desktop.
Call Mailgun API from node.js with Request and Parse-Server
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') | |
Parse.Cloud.define("sendemail", function(req, res) { | |
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); | |
res.error(err.message); | |
} else { | |
console.log('email sent!'); | |
res.success('ok') | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment