Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodemailer - Works locally but not on production

https://gist.github.com/anonymous/ba82f74071cc38a0700b

Before changing some settings, e.g. host and port, it was working fine locally, but just won't work on production.

Anyone know why?

Thanks

like image 246
Mod Mark Avatar asked Mar 29 '16 09:03

Mod Mark


2 Answers

i think this is happening because of port number and your firewall at this port is not allowing you to send mail over this port(80) . try with 587 or 465 which are actually the standard port number for SMTP.

changed your code a bit

/**
 * Created by atul on 29/3/16.
 */

var nodemailer = require('nodemailer');
transporter = nodemailer.createTransport({
  service: 'Gmail',
  //host: 'myhost',
  port: 465,
  secure: true,
  auth: {
    user: '[email protected]',
    pass: 'mypassword'
  }
});
  mailOptions = {
    from: '[email protected]',
    to: '[email protected]',
    subject: 'You received a new message at !',
    text: 'Hello Mailer',
html: ''
};
transporter.sendMail(mailOptions, function(error, info){
  if(error){
  console.log(error)
}else{
  console.log('Message sent: ' + info.response)
}
});
like image 34
Atul Agrawal Avatar answered Sep 27 '22 00:09

Atul Agrawal


Disable Captcha temporarily so you can mail using new server,

https://accounts.google.com/b/0/displayunlockcaptcha

like image 176
Anjal Saneen Avatar answered Sep 23 '22 00:09

Anjal Saneen