Last active
March 27, 2017 14:22
-
-
Save itswadesh/4142a06362689cd4deefbbd1bf0a9694 to your computer and use it in GitHub Desktop.
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'); | |
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