Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

node.js - Nodemailer - Error: connect ETIMEDOUT 216.58.221.36:587

I have an api which sends email when a user submits data on the frontend. I can't get the nodemailer sendmail to work.

nodemailer.js -

const nodemailer = require("nodemailer");

async function sendmail(data) {
  let transporter = nodemailer.createTransport({
    host: "www.google.com",
    port: 587,
    secure: false,
    auth: {
      user: <my email>,
      pass: <password>,
    },
  });

  await transporter.sendMail(
    {
      from: data.email,
      to: <my email>, 
      subject: "CEWA Feedback", 
      text: data.message,
      html: "<b>Hello world?</b>",
    },
    (err) => {
      console.log(err);
    }
  );
}

module.exports = sendmail;

When this function runs I get this error in the console -

Error: connect ETIMEDOUT 216.58.221.36:587
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
  errno: 'ETIMEDOUT',
  code: 'ESOCKET',
  syscall: 'connect',
  address: '216.58.221.36',
  port: 587,
  command: 'CONN'
}

Any idea what's going wrong? Thanks in advance.

question from:https://stackoverflow.com/questions/65871796/nodemailer-error-connect-etimedout-216-58-221-36587

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

can you try adding tls config to the transporter object

     let transporter = nodemailer.createTransport({
        service: 'gmail',
        host: 'smtp.gmail.com', 

        auth: {
          user: <my email>,
          pass: <password>,
        },
        tls: {rejectUnauthorized: false}
      });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...