从localhost(使用nodejs+ express)发送电子邮件,抛出;

发布于 2025-02-07 17:43:28 字数 789 浏览 2 评论 0原文

我设置了SendGrid电子邮件API SMTP服务,以从我的应用程序发送电子邮件(使用带有Express的Nodejs)。在从Local主持的主机发送电子邮件时,我会收到以下错误:

Error: unable to get local issuer certificate
    at TLSSocket.onConnectSecure (node:_tls_wrap:1532:34)
    at TLSSocket.emit (node:events:527:28)
    at TLSSocket._finishInit (node:_tls_wrap:946:8)
    at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:727:12) {
  code: 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY'

我尝试了禁用选项并使用启用SSL证书,但没有运气。

npm set strict-ssl=false
npm config set registry http://registry.npmjs.org/
npm config set cafile *.pem

I also tried setting the certificates(DigiCertGlobalRootCA & DigiCertTLSECCP384RootG5.crt.pem) on nodejs server startup(refer

您能帮我解决这个问题吗?我们是否需要CA证书来发送电子邮件,如何解决此问题,如何在Nodejs中设置证书?

I have setup SendGrid Email API SMTP service to send email from my app(using NodeJS with express). On sending email from my localhost, I get the below error:

Error: unable to get local issuer certificate
    at TLSSocket.onConnectSecure (node:_tls_wrap:1532:34)
    at TLSSocket.emit (node:events:527:28)
    at TLSSocket._finishInit (node:_tls_wrap:946:8)
    at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:727:12) {
  code: 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY'

I tried options to disable and also with enable SSL certificates, but no luck.

npm set strict-ssl=false
npm config set registry http://registry.npmjs.org/
npm config set cafile *.pem

I also tried setting the certificates(DigiCertGlobalRootCA & DigiCertTLSECCP384RootG5.crt.pem) on nodejs server startup(refer https://www.sitepoint.com/how-to-use-ssltls-with-node-js/) but end up with same error.

Can you help me on resolving this issue. Do we need the CA certificates to send emails, how do I fix this problem, how do I set the certificates in NodeJS?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尤怨 2025-02-14 17:43:28

我有同样的问题。在公司笔记本电脑上运行,但不在VPN中运行,即在公司网络中运行。
邮递员正常工作!
一位同事告诉我,我们在笔记本电脑上有一个“本地代理”,我需要经过此操作。而且由于此代理具有自签名证书,因此我需要禁用SSL验证或将其添加到信托店。
对我来说有点了解。

const sgMail = require('@sendgrid/mail')
const apiKey = process.env.SENDGRID_API_KEY;

sgMail.setApiKey(apiKey)
const msg = {
  to: '[email protected]',
  from: '[email protected]',
  subject: 'SendGrid test',
  text: 'Easy to do anywhere, even with Node.js'
}
sgMail
  .send(msg)
  .then(() => {
     console.log('Email sent')
  })
  .catch((error) => {
     console.error(error)
})

I have the same problem. Running on company laptop but not in VPN, that is, not in the corporate network.
Postman works fine!
A colleague told me that we have a "local Proxy" on the laptop and I need to go through this. And because this proxy has a self signed cert, I need to disable SSL validation or add it to a truststore.
Is a bit much for me to understand.

const sgMail = require('@sendgrid/mail')
const apiKey = process.env.SENDGRID_API_KEY;

sgMail.setApiKey(apiKey)
const msg = {
  to: '[email protected]',
  from: '[email protected]',
  subject: 'SendGrid test',
  text: 'Easy to do anywhere, even with Node.js'
}
sgMail
  .send(msg)
  .then(() => {
     console.log('Email sent')
  })
  .catch((error) => {
     console.error(error)
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文