2016-11-06 2 views
1

실행 된 모든 테스트 후에 테스트 결과가 포함 된 전자 메일을 보내려고합니다.모카의 애프터 훅에서 센드 메일 전송 콜백을 호출하지 않았습니다.

후크에서 sendMail (nodemailer)을 호출하면 작동하지 않습니다.

내 코드

:

after(function(done) { 
    sendReport(); 
    done(); 
}); 


function sendReport() { 
    let mailOptions = { 
     from: "[email protected]", 
     to: "[email protected]", 
     subject: "subject", 
     text: "body Text", 
     html: "<h2><b>TEXT.</b></h2>", 
     attachments: [{ 
      path: "../reports/report.html" 
     }] 
    }; 

    let transporter = nodemailer.createTransport({ 
     service: "Gmail", 
     auth: { 
      user: "[email protected]", 
      pass: "xxxx" 
     } 
    }); 

    transporter.sendMail(mailOptions, function (error, info) { 
     if (error) { 
      console.log(error); 
     } 
    }); 
} 
+0

당신은'done' 콜백을 호출해야합니다 후 ** 메일이 발송되었습니다 ** (마음 asynchronity) – qqilihq

답변

2

이메일을 전송 한 후 done 콜백을 실행

after(function(done) { 
    sendReport(done); 
}); 


function sendReport(done) { 
    let mailOptions = { 
     from: "[email protected]", 
     to: "[email protected]", 
     subject: "subject", 
     text: "body Text", 
     html: "<h2><b>TEXT.</b></h2>", 
     attachments: [{ 
      path: "../reports/report.html" 
     }] 
    }; 

    let transporter = nodemailer.createTransport({ 
     service: "Gmail", 
     auth: { 
      user: "[email protected]", 
      pass: "xxxx" 
     } 
    }); 

    transporter.sendMail(mailOptions, function (error, info) { 
     if (error) { 
      console.log(error); 
     } 
     done(); 
    }); 
} 
+0

큰! 고맙습니다. –

관련 문제