5

I am using nodemailer to send email from ec2 server but it is getting timeout

var nodemailer = require('nodemailer');
var smtpConfig =   {
                     service : 'Gmail',
                     secure : true,
                     auth   : {
                        user: 'adminemail@gmail.com',
                        pass: 'password'
                    }
                };
var smtpTransport  =   nodemailer.createTransport(smtpConfig);

smtpTransport.sendMail({
      from    : '"Admin" < adminemail@gmail.com >',
      to      : 'user@gmail.com',
      subject : 'click on link',
      html    : 'Please click on link'
   }, 
   function(err, res){
            if(err){
                console.log("email send error",err);
            }else{
                console.log("On Email Send Success : ", res);
            }
});

The above code is working fine on localhost but when i tried on live server running on EC2, it is getting timeout

email send error { [Error: Connection timeout] code: 'ETIMEDOUT' }

Please suggest a way to modify the code

rkrock
  • 69
  • 7
  • What about setting `port: 465` or `port: 587` inside `smtpConfig`? EC2 heavily [throttles](https://aws.amazon.com/premiumsupport/knowledge-center/ec2-port-25-throttle/) port 25 (presumably, since you aren't setting it, that's what's being used by default) for obvious reasons, but not the other ports, which are more correct anyway. Does that help? – Michael - sqlbot Oct 09 '16 at 21:13
  • I also checked with port 465 and host 'smtp.gmail.com' – rkrock Oct 10 '16 at 07:20
  • Same issue us occuring, email sent is successful on localhost only – rkrock Oct 10 '16 at 07:21
  • Is there any setup i need to do on amazon route 53 for email – rkrock Oct 10 '16 at 07:22
  • Nothing is needed in Route 53 in order to send outgoing email through Gmail. Have you confirmed that this instance actually has outbound connectivity, using standard command line tools? – Michael - sqlbot Oct 10 '16 at 10:26
  • Got the error. port 465 was not enabled on EC2 – rkrock Oct 10 '16 at 12:32
  • Thanks for the quick reply – rkrock Oct 10 '16 at 12:34

0 Answers0