0

i tried using nodemailer to send emails from my outlook account to other accounts but i keep getting this error.

Error: Invalid greeting. response=421 Service not available: 421 Service not available code: 'EPROTOCOL', response: '421 Service not available', responseCode: 421, command: 'CONN'

Here is my code

const nodemailer = require("nodemailer");

module.exports = function OTP() {
  // Sends otp link to and code to user
  return new Promise((resolve, reject) => {
    const transporter = nodemailer.createTransport({
      service: "hotmail",
      port: "25",
      secure: true,
      auth: {
        user: process.env.EMAIL, //Outlook email
        pass: process.env.EMAIL_PASSWORD,
      },
      tls: {
        ciphers: "SSLv3",
      },
    });
    transporter.sendMail(
      {
        from: process.env.EMAIL,
        to: email,
        subject: "Test",
        text: `
        
        `,
      },
      (err, info) => {
        if (err) {
          console.log(err);
          return reject({ message: "An error has occurred" });
        } else return resolve({ message: "Email sent" });
      }
    );
  });
};

i tried changing the port and switching to gmail but i get the same error.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
CODE101
  • 1
  • 2

1 Answers1

1

I had this same error but in nestjs and this is my solution that you can try.

First in my configuration I did not define a port and my secure was set to false, so port was default to 587. I was sending mail and everything was fine untill one day I started to get the same error as you are getting now. so here is my fix

  1. I use telnet to test my connection to the mail server:

    a. Open terminal and type: telnet your_domain 587. eg

    telnet smtp.sendgrid.net 587

    I got 421 Service not available

  2. I change secure to true which will now default the port to 465 and I try telnet again, this time

    telnet smtp.sendgrid.net 465

    I got no error. I test the endpoint again and everything works fine.

I hope this helps

Reference:

stackoverflow

nodemailersmtp