Created
March 4, 2013 17:08
-
-
Save theycallmeswift/5083776 to your computer and use it in GitHub Desktop.
A simple node sendgrid proxy
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
var express = require('express') | |
, app = express() | |
, SendGrid = require('sendgrid').SendGrid | |
, sg = new SendGrid(process.env.SENDGRID_USER, process.env.SENDGRID_PASS); | |
app.use(express.logger()); | |
app.use(express.bodyParser()); | |
app.post('/email', function(req, res) { | |
if(!req.body.to || !req.body.subject || !req.body.html) { | |
res.statusCode = 400; | |
res.send({ status: "error", msg: "Missing required parameters" }); | |
res.end(); | |
} | |
sg.send({ | |
to: req.body.to, | |
from: "you@yourdomain.com", | |
subject: req.body.subject, | |
html: req.body.html | |
}, function(success, msg) { | |
if(!success) { | |
res.statusCode = 500; | |
res.send({ status: "error", msg: msg }); | |
return res.end(); | |
} | |
res.send({ status: "ok" }); | |
}); | |
}); | |
app.listen(process.env.PORT || 3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment