Skip to content

Instantly share code, notes, and snippets.

@theycallmeswift
Created March 4, 2013 17:08
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 theycallmeswift/5083776 to your computer and use it in GitHub Desktop.
Save theycallmeswift/5083776 to your computer and use it in GitHub Desktop.
A simple node sendgrid proxy
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