【问题标题】:Nodemailer not working when i deployed to vercel当我部署到 Vercel 时,Nodemailer 不工作
【发布时间】:2023-02-25 14:50:41
【问题描述】:

我在我的网页上创建了一个表单,并使用 nodemailer 将电子邮件发送到我的 gmail 帐户。我使用的主机是 gmail。一切都在开发中,但是当我部署到 Vercel 时,我在使用表单时没有收到任何电子邮件。我试过 async 和 await 但它仍然不起作用。当我检查 Vercel 上的功能日志时,在某些情况下我会收到此错误

Error: Greeting never received
    at SMTPConnection._formatError (/var/task/node_modules/nodemailer/lib/smtp-connection/index.js:790:19)
    at SMTPConnection._onError (/var/task/node_modules/nodemailer/lib/smtp-connection/index.js:776:20)
    at Timeout.<anonymous> (/var/task/node_modules/nodemailer/lib/smtp-connection/index.js:710:22)
    at listOnTimeout (node:internal/timers:564:17)
    at processTimers (node:internal/timers:507:7) {
  code: 'ETIMEDOUT',
  command: 'CONN'
}

这是我的运输车

  const transporter = NodeMailer.createTransport({
    service: 'gmail',
    secure: true,
    auth: {
      user: 'fifthtribe05@gmail.com',
      pass: <secretPass>
    }
  });

发送邮件

const mailOptions = {
    from: email,
    to: 'email@gmail.com',
    subject: 'Subject',
    text: `${message} from ${email}`
  };
  
  const sendMessage = async(mailOptions:any)=> { 
    await transporter.sendMail(mailOptions, function(error: any, info: { response: string; }){
    console.log("sending");
    console.log(error);

    if (error) {
      console.log(error);
    } else {
      console.log('Email sent: ' + info.response);
    }
  })};
  await sendMessage(mailOptions);

请我需要帮助或者是否有任何其他选择



Ive read other similar issues on satckoverflow and github. 
1. I've added async and await
2. Ive added secure true
3. it works in development but not in production (vercel)

【问题讨论】:

    标签: reactjs nodemailer remix


    【解决方案1】:

    好吧,当我在为同样的错误寻找解决方案时,我看到这个没有答案,我不知何故想通了。您需要做的就是将端口添加为 465;

    {
      port: 465
    }

    因为这是一项安全服务。有了这个,它应该可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-30
      • 2020-01-13
      • 2023-02-12
      • 1970-01-01
      • 2022-01-02
      • 2020-09-05
      • 2022-01-25
      • 2022-01-11
      相关资源
      最近更新 更多