Skip to content

Instantly share code, notes, and snippets.

@itswadesh
Last active March 27, 2017 14:22
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 itswadesh/4142a06362689cd4deefbbd1bf0a9694 to your computer and use it in GitHub Desktop.
Save itswadesh/4142a06362689cd4deefbbd1bf0a9694 to your computer and use it in GitHub Desktop.
var express = require('express');
var bodyParser = require('body-parser');
var nodemailer = require('nodemailer');
var sgTransport = require('nodemailer-sendgrid-transport');
var app = express();
app.use(express.static(__dirname + '/client'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Sendmail route
app.post('/sendmail', function(req, res){
var options = {
auth: {
api_key: 'YOUR_SENDGRID_API_KEY'
}
}
var mailer = nodemailer.createTransport(sgTransport(options));
mailer.sendMail(req.body, function(error, info){
if(error){
res.status('401').json({err: info});
}else{
res.status('200').json({success: true});
}
});
});
// Start server
var port = 8080, ip = "127.0.0.1";
app.listen(port, ip, function() {
console.log('Express server listening on http://localhost:%d', port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment