Created
January 7, 2017 19:49
-
-
Save Mikeysauce/f1ba0f2a69023a35b02ed7d7543bc676 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import express from 'express'; | |
import path from 'path'; | |
import isEmpty from 'lodash/isEmpty'; | |
import mailer from 'express-mailer'; | |
import dotenv from 'dotenv'; | |
dotenv.load(); | |
const app = express(); | |
const router = express.Router(); | |
const user = process.env.MAIL_USER; | |
const pass = process.env.MAIL_PASSWORD; | |
const emailFrom = process.env.MAIL_EMAIL_FROM; | |
const emailHost = process.env.MAIL_EMAIL_HOST; | |
const emailPort = process.env.MAIL_port; | |
app.set('views', path.join(__dirname, '../../views')); | |
app.set('view engine', 'jade'); | |
mailer.extend(app, { | |
from: emailFrom, | |
host: emailHost, // hostname | |
secureConnection: true, // use SSL | |
port: emailPort, // port for secure SMTP | |
transportMethod: 'SMTP', // default is SMTP. Accepts anything that nodemailer accepts | |
auth: { | |
user, | |
pass | |
} | |
}); | |
router.post('/', (req, res) => { | |
const { name, message, email } = req.body; | |
app.mailer.send('email', { | |
to: email, | |
name, | |
subject: `Welcome ${name}`, | |
message | |
}, (err) => { | |
if (err) { | |
res.status(500).json({ error: err.data }); | |
return; | |
} | |
res.json({ success: true }); | |
}); | |
}); | |
export default router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment