2017-07-26 156 views
0

我正在使用NodeMailer發送電子郵件。我已經成功地使用我的Gmail帳戶發送電子郵件。我只是通過Godaddy切換到我的域名自定義電子郵件。這封電子郵件通過hotmail運行。現在我已經做了這個開關,我每次都得到錯誤:連接超時。 Gmail仍然有效,但我無法使用Hotmail工作。NodeMailer:錯誤:連接超時

有關如何解決此問題的任何建議?有沒有更好的電子郵件選擇用於NodeMailer?

這裏是我的設立:

var smtpTrans = nodemailer.createTransport({ 
     service: 'hotmail', 
     auth: { 
      user: '[email protected]', 
      pass: '*********' 
     } 
     }); 
     var mailOptions = { 
     to: rental.createdbyemail, 
     from: 'email', 
     subject: 'Your apartment was just rented!', 
     text: 'my email' 
     }; 
     smtpTrans.sendMail(mailOptions, function(err) { 
     console.log('email sent') 
     if (err){ 
     console.log(err) 
     } else { 
     // res.redirect('/') 
     } 
     }); 
} 
}); 

回答

0

做了一些研究之後看起來像SendGrid是要走的道路使用專用電子郵件系統。看看這個guide

代碼設置:

// emailer.js 
const nodemailer = require('nodemailer'); 
const sendgridTransport = require('nodemailer-sendgrid-transport'); 

// Configure Nodemailer SendGrid Transporter 
const transporter = nodemailer.createTransport(
    sendgridTransport({ 
    auth: { 
     api_user: process.env.SENDGRID_API_USER, // SG username 
     api_key: process.env.SENDGRID_API_PASSWORD, // SG password 
    }, 
    }) 
); 

// Create Email Options 
const options = { 
    to: <[email protected]>, 
    from: <[email protected]>, // Totally up to you 
    subject: <email_subject>, 
    html: <html_body>,    // For sending HTML emails 
}; 

// Send Email 
transporter.sendEmail(options, (err, resp) => { 
    if (err) { 
    // handle error 
    } else { 
    // handle success 
    } 
}); 
+0

嘿,我有同樣的問題,但我不明白爲什麼它會給出一個連接超時,如果它是一個寒冷的知識產權問題。如果發送網格是一個更好的可信解決方案,那麼gmail會拒絕該電子郵件嗎?爲什麼會超時? –

+0

@RakshithRavi嘿!我相信有一個超時,因爲它試圖連接到郵件服務器,並花了很長時間來這樣做。 (只是猜測。)我無法使用我的Hotmail電子郵件地址工作,因爲它無法足夠快地連接。發送網格電子郵件的工作非常出色 – AndrewLeonardi

+1

嗯,我不能接受SendGrid能夠做我們做不到的事情。我使用https和letsencrypt證書設置了我的服務器。我會接受挑戰,讓它在沒有sendgrid的情況下工作!哈哈!一旦我有了進展,我會盡快回復您。P –