When I send email with attachments, it is sent 2 times, why?
´´´
function beforeRender(req, res, done) {
req.options = req.options || {}
req.options.preview = false
require('request')({
url:"http:",
json:true
}, function(err, response, body){
console.log(JSON.stringify(body))
req.data = Object.assign({}, req.data, { terpel: body })
done();
});
return;
}
function afterRender(req, res, done) {
if (req.options && req.options.preview) {
return done()
}
var mailer = require("nodemailer");
var smtpTransport = mailer.createTransport(
'smtps://example%40hotmail.com:Sistemas@hotmail.com'
);
var mail = {
from: "Marlon<example@hotmail.com>",
to: "example@hotmail.com",
subject: "Formato ",
text: "Formato " ,
html: "Buenos días,",
attachments: [
{
filename: "Formato".xlsx",
content: new Buffer(res.content)
}],
}
smtpTransport.sendMail(mail, function(error, response){
smtpTransport.close();
if(error){
return done(error);
}
return done();
});
}
´´´