I send mail



  • 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();
    });
    

    }
    ´´´



  • Please try to add to the afterRender this code:

    if (req.context.isChildRequest) {
       return
    }
    

    or

    if (req.options.isChildRequest) {
       return
    }
    

    It depends based on the jsreport version you use.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.