Skip to content

Instantly share code, notes, and snippets.

@rbren
Last active May 30, 2019 23:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbren/ceb9a16e30391bb1aeea83439bc724ef to your computer and use it in GitHub Desktop.
Save rbren/ceb9a16e30391bb1aeea83439bc724ef to your computer and use it in GitHub Desktop.
let app = require('express')();
app.use(require('body-parser').urlencoded());
const CONTACT_ADDRESS = 'me@company.com';
var mailer = require('nodemailer').createTransport({
service: 'Gmail',
auth: {
user: process.env.GMAIL_ADDRESS,
pass: process.env.GMAIL_PASSWORD,
}
});
app.post('/contact', function(req, res) {
mailer.sendMail({
from: req.body.from,
to: [CONTACT_ADDRESS],
subject: req.body.subject || '[No subject]',
html: req.body.message || '[No message]',
}, function(err, info) {
if (err) return res.status(500).send(err);
res.json({success: true});
})
});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment