Node.js节点邮件程序错误-版本号错误/问候语无效

slhcrj9b  于 2022-12-22  发布在  Node.js
关注(0)|答案(6)|浏览(249)

我在node.js服务器上设置nodemailer时遇到了一个大问题。我试了所有在互联网上找到的东西,但都没有用。唯一容易设置的是gmail服务。但不幸的是我不能使用那个。
secure设置为true时,我得到一个ssl错误,原因是版本代码错误

[Error: 22468:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332:
] {
  library: 'SSL routines',
  function: 'ssl3_get_record',
  reason: 'wrong version number',
  code: 'ESOCKET',
  command: 'CONN'
}

但是当我尝试将secure设置为false时,我收到了invalid greeting错误

Error: Invalid greeting. response=* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA ACL ACL2=UNION STARTTLS] Courier-IMAP ready. Copyright 1998-2016 Double Precision, Inc.  See COPYING for distribution information.: * OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA ACL ACL2=UNION STARTTLS] Courier-IMAP ready. Copyright 1998-2016 Double Precision, Inc.  See COPYING for distribution information.
    at SMTPConnection._actionGreeting (C:\Users\Motiondata\Documents\repos\rmn_app\server\rmn_server\node_modules\nodemailer\lib\smtp-connection\index.js:1189:27)
    at SMTPConnection._processResponse (C:\Users\Motiondata\Documents\repos\rmn_app\server\rmn_server\node_modules\nodemailer\lib\smtp-connection\index.js:932:20)
    at SMTPConnection._onData (C:\Users\Motiondata\Documents\repos\rmn_app\server\rmn_server\node_modules\nodemailer\lib\smtp-connection\index.js:739:14)
    at Socket.SMTPConnection._onSocketData (C:\Users\Motiondata\Documents\repos\rmn_app\server\rmn_server\node_modules\nodemailer\lib\smtp-connection\index.js:189:44)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:284:9)
    at Socket.Readable.push (_stream_readable.js:223:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
  code: 'EPROTOCOL',
  response: '* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA ACL ACL2=UNION STARTTLS] Courier-IMAP ready. Copyright 1998-2016 Double Precision, Inc.  See COPYING for distribution information.',
  command: 'CONN'
}

我的代码如下:

const transporter = nodemailer.createTransport({
  host: process.env.MAIL_HOST, // mx.example.com
  port: process.env.MAIL_PORT, // 143
  secure: true,
  auth: {
    user: process.env.MAIL_ADDRESS,
    pass: process.env.MAIL_PWD
  }
})

我检查了一千次证件,他们肯定不是问题。
希望有人能帮助我。先谢了。

b5buobof

b5buobof1#

参考此处提到的问题:https://github.com/andris9/Nodemailer/issues/165
添加tls.ciphers选项以使用SSLv3,看看是否有帮助:

const transport = nodemailer.createTransport({
    host: process.env.MAIL_HOST, // mx.example.com
    port: process.env.MAIL_PORT, // 143
    secureConnection: false, // TLS requires secureConnection to be false
    auth: {
        user: process.env.MAIL_ADDRESS,
        pass: process.env.MAIL_PWD
    },
    tls: {
        ciphers:'SSLv3'
    }
});

对于Outlook365,这应该有效:

service: "Outlook365",
auth: {
   user: '[YOUR_O365_EMAIL]',
   pass: '[YOUR_O365_PASSWORD]'
},

参考此处:https://stackoverflow.com/a/37725123/9360885
如果您使用的是HotMail,则删除hostport,只添加service: "hotmail"

pzfprimi

pzfprimi2#

使用
第一个月
来自节点邮件程序文档的示例:

let transporter = nodemailer.createTransport({
    host: 'smtp.ethereal.email',
    port: 587,
    secure: false, // true for 465, false for other ports
    auth: {
        user: account.user, // generated ethereal user
        pass: account.pass  // generated ethereal password
    }
});

来源:nodemailer示例

nzrxty8p

nzrxty8p3#

我在Gmail中使用了端口465,效果很好。在587中出现了“版本号错误”的错误。下面的示例是云功能中的GCP服务帐户。

const transporter = nodemailer.createTransport({
    host: "smtp.gmail.com",
    port: 465,
    secure: true,
    auth: {
      type: "OAuth2",
      user: process.env.GMAIL_ADDRESS,
      serviceClient: process.env.CLIENT_ID,
      privateKey: process.env.PRIVATE_KEY.replace(/\\n/g, "\n"),
    },
  });
kgsdhlau

kgsdhlau4#

我也遇到过这个问题。但我设法解决了。它很容易解决。

溶液:port: process.env.MAIL_PORT * 1

这会将您的process.env.MAIL_PORT类型从字符串更改为整数

为什么会出现错误?

NodeMail要求端口类型为integer,但您传递的是字符串。因此导致错误。

a0x5cqrl

a0x5cqrl5#

如果您仍然收到该问题,请在登录时手动将其输入到浏览器中进行修复。
https://accounts.google.com/DisplayUnlockCaptcha

gg58donl

gg58donl6#

更改smtp端口587到465

smtp:{
    name:"noreply@gmail.com",
    host:process.env.SMTP_HOST, 
    secure: true,//true
    port: 465,//465
    auth: {
      user: process.env.SMTP_USER, 
      pass: process.env.SMTP_PASSWORD, 
    },  // here it goes
  },

相关问题