【问题标题】:Nodemailer - Error: connect ETIMEDOUT 216.58.221.36:587Nodemailer - 错误:连接 ETIMEDOUT 216.58.221.36:587
【发布时间】:2021-01-24 14:31:45
【问题描述】:

我有一个 api,当用户在前端提交数据时发送电子邮件。我无法让 nodemailer sendmail 工作。

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;

当此函数运行时,我在控制台中收到此错误 -

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'
}

知道出了什么问题吗?提前致谢。

【问题讨论】:

    标签: node.js express nodemailer


    【解决方案1】:

    您可以尝试将 tls 配置添加到传输器对象吗

         let transporter = nodemailer.createTransport({
            service: 'gmail',
            host: 'smtp.gmail.com', 
    
            auth: {
              user: <my email>,
              pass: <password>,
            },
            tls: {rejectUnauthorized: false}
          });
    

    【讨论】:

    • 您确定主机是 google.com 吗?由于 gmail 的服务名称不同。
    • 我不确定。我应该保留默认主机smtp.ethereal.email 吗?
    • 更新了使用gmail服务的答案
    • Error: Invalid login: 535-5.7.8 Username and Password not accepted 我现在收到此错误
    猜你喜欢
    • 2022-11-03
    • 2019-12-24
    • 2021-02-22
    • 1970-01-01
    • 1970-01-01
    • 2020-08-09
    • 1970-01-01
    • 1970-01-01
    • 2017-02-13
    相关资源
    最近更新 更多