Last active
January 7, 2020 22:54
-
-
Save akobashikawa/5270e5d4c1374f86e0bbc814d42cd76a to your computer and use it in GitHub Desktop.
Ejemplo uso de mailer en express app
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
const mailer = require('express-mailer'); | |
//.. | |
app.set('views', path.join(__dirname, 'views')); | |
app.set('view engine', 'ejs'); | |
//... | |
const GMAIL_USER = process.env.GMAIL_USER; | |
const GMAIL_PASSWORD = process.env.GMAIL_PASSWORD; | |
mailer.extend(app, { | |
from: 'no-reply@aviva.pe', | |
host: 'smtp.gmail.com', // hostname | |
secureConnection: true, // use SSL | |
port: 465, // port for secure SMTP | |
transportMethod: 'SMTP', // default is SMTP. Accepts anything that nodemailer accepts | |
auth: { | |
user: GMAIL_USER, | |
pass: GMAIL_PASSWORD | |
} | |
}); | |
//... | |
app.post('/test', (req, res) => { | |
const mailerData = { | |
to: req.body.to, | |
bcc: req.body.bcc, | |
subject: req.body.subject, | |
extra: 'texto libre', | |
body: req.body.message, | |
}; | |
// usar vista views/mail | |
mailerSend('./views/mail', mailerData).then((mailerResult) => { | |
return res.json({ mailerData, mailerResult }); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment