Created
July 20, 2017 19:08
-
-
Save masterk63/e3aa79ceea3ca97e43a4ef8ce925a296 to your computer and use it in GitHub Desktop.
generar mail con archivo adjunto buffer
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
router.get('/email',function (req, res) { | |
var pdf = require('html-pdf'); | |
var fs = require('fs'); | |
var html = '<h3>hola</h3><p>chau</p>' | |
var transporter = nodemailer.createTransport({ | |
host: 'smtp.gmail.com', // mail.clubhonorarios.com | |
port: 587, | |
auth: { | |
user: 'ejemplo@gmail.com', | |
pass: 'ejemplo' | |
} | |
}); | |
pdf.create(html).toStream(function(err, stream){ | |
var mailOptions = { | |
from: 'Club Honorarios <ch@clubhonorarios.com>', //grab form data from the request body object | |
to: 'rbrunount@gmail.com', | |
subject: 'PDF', | |
text: 'holaaa node cuerpo!!!', | |
attachments: [ | |
{ // stream as an attachment | |
filename: 'ejemplo.pdf', | |
content: stream | |
}], | |
}; | |
transporter.sendMail(mailOptions,function(error, info){ | |
if(error){ | |
console.log(error); | |
res.json({yo: 'error'}); | |
}else{ | |
console.log('Message sent: ' + info.response); | |
res.json({yo: info.response}); | |
}; | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment