Skip to content

Instantly share code, notes, and snippets.

@ingeit
Created July 28, 2017 14:54
Show Gist options
  • Save ingeit/9f3e762cbc8cdb786853948d5a6c7748 to your computer and use it in GitHub Desktop.
Save ingeit/9f3e762cbc8cdb786853948d5a6c7748 to your computer and use it in GitHub Desktop.
generar mail con archivo adjunto buffer
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