2

I am trying to send email using nodemailer using godaddy smtp server(secureserver.net).

On my local machine code works fine but when I deploy same code on aws server it gives Error: Connection timeout.

Here is my code

const nodemailer = require('nodemailer');

let transporter = nodemailer.createTransport({
    service: 'Godaddy',
    host: 'smtpout.secureserver.net',
    secureConnection: true,
    port: 465,

    auth: {
        user: 'xxx@zzzzzz.com',
        pass: '*******'
    }
});

let mailOptions = {
    from: 'xxx@zzzzzz.com',
    to: 'aaaa@gmail.com',
    subject: 'Test sub',
    html: 'Test body'
};

transporter.sendMail(mailOptions, function (error, info) {
    if (error) {
        console.log(error);
    } else {
        console.log('Email sent: ' + info.response);
    }
});

I have added port 465/25 in outbound port list for the server

Please let me know any workaround this?

ak_arjun
  • 33
  • 1
  • 1
  • 6

1 Answers1

0

(Solution - Latest) This one has worked successfully.

static transport = nodeMailer.createTransport({
// service: 'Godaddy', <--- Dont add this anymore --->
host: 'smtpout.secureserver.net',
port: 465,
auth: {
  user: config.get('application.mail.MAIL_SENDER'),
  pass: config.get('application.mail.MAIL_SENDER_PASSWORD')
},
  tls: { rejectUnauthorized: false }
});

SendMailService.transport.sendMail(mailOptions, function (error: Error, response: SentMessageInfo) {
  if (error) {
    loggerService.logError(' Error in mail send ' + error);
  }
  loggerService.logDebug(' response in mail send ' + response);
  callback(error, response);
});

This has worked in my case. I am using GoDaddy professional mail service. I was also getting connection refused and connection timeout for some changes but this one(above mentioned code had worked).

If still there is an issue then check for DNS records whether it is pointing properly under "My Domain >> DNS >> DNS management". Over there check for A type and MX.

  • I tried your code but getting Error: connect ETIMEDOUT 173.201.192.229:25 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) It was working earlier when I implemented it. Do you have any idea why this is getting time out? – Jayna Tanawala Apr 26 '21 at 12:07