i'm facing problems using nodemailer module in node.js single gear non-scalable application in openshift. documentation suggested, initialized transporter object , used sendmail function. simplified version of code is
var transporter = nodemailer.createtransport({ service: 'gmail', auth: { user: 'my.mail@gmail.com', pass: 'mypassword' } }); var mail = { from: 'my.mail@gmail.com', to: 'test@mydomain.com', subject: 'test mail', html: 'test mail' }; transporter.sendmail(mail, function(error, info) { if(error){ console.log(error); }else{ console.log(info); } }); this code works correctly when run on local machine, when try execute on server got etimedout error, if application couln't connect smtp server.
{ [error: connect etimedout] code: 'etimedout', errno: 'etimedout', syscall: 'connect' } i've tried increase timeout connection parameter, got same results.
var transporter = nodemailer.createtransport({ service: 'gmail', auth: { user: 'my.mail@gmail.com', pass: 'mypassword' }, connectiontimeout: 5 * 60 * 1000, // 5 min }); is there firewall or default openshift settings or enviroment variable i'm missing?
i've run few more tests, think figured out problem was. authentication via username , password not-secure authentication method gmail. written in nodemailer documentation
even though gmail fastest way started sending emails, no means preferable solution unless using oauth2 authentication. gmail expects user actual user not robot runs lot of heuristics every login attempt , blocks looks suspicious defend user account hijacking attempts. example might run trouble if server in geographical location – works in dev machine messages blocked in production.
i upgraded authorization method using xoauth2, explained in guide , mails correctly sent.
Comments
Post a Comment