2012-01-30 51 views
1

我在使用nodeJS發送電子郵件(使用nodemailer lib),並且我目前在整個郵件處理過程中遇到了一些超時。這不是我需要幫助的問題。我需要幫助的問題是,當它到達日誌記錄部分時,成功將爲空,並且sole.log('Message'+使整個console.log語句輸出「已發送」。沒有「消息」,沒有失敗?成功? '發送':'失敗'默認爲'發送'成功=空。爲什麼?

任何想法,爲什麼

nodemailer.send_mail(
       // e-mail options 
       { 
        to:"[email protected]", 
        sender:"[email protected]", 
        subject:"node_mailer test email", 
        html:'<p><b>Hi,</b> how are you doing?</p>', 
        body:'Hi, how are you doing?' 
       }, 
       // callback function 
       function(error, success){ 
        console.log('Message ' + success ? 'sent' : 'failed'); 
       } 
      ); 
+1

我認爲它檢查''Message'+ success'是否爲null,它永遠不會是,所以它總是如此。 – Ivan 2012-01-30 17:16:02

回答

4

運算符優先級嘗試:

'Message ' + (success ? 'sent' : 'failed') 
2

這是你的業務的優先級+操作符比三元運算符優先級高,正因爲如此,你。實際上是在做

console.log(('Message ' + success) ? 'sent' : 'failed'); 

這總是如此。相反,請執行以下操作:

console.log('Message ' + (success ? 'sent' : 'failed'));