Created
July 28, 2017 14:54
-
-
Save ingeit/9f3e762cbc8cdb786853948d5a6c7748 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