Skip to content

Instantly share code, notes, and snippets.

@akobashikawa
Last active January 7, 2020 22:54
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 akobashikawa/5270e5d4c1374f86e0bbc814d42cd76a to your computer and use it in GitHub Desktop.
Save akobashikawa/5270e5d4c1374f86e0bbc814d42cd76a to your computer and use it in GitHub Desktop.
Ejemplo uso de mailer en express app
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