繁体   English   中英

Nodemailer 6.1.1 不适用于 NodeJs >=12

[英]Nodemailer 6.1.1 not working with NodeJs >=12

我有一个行为nodemailer更新我的时候nodejs版本12

现在,当我尝试发送电子邮件时,我得到:

DEBUG Creating transport: nodemailer (6.1.1; +https://nodemailer.com/; SMTP/6.1.1[client:6.1.1])
DEBUG Sending mail using SMTP/6.1.1[client:6.1.1]
DEBUG [9mzLKQAwcwQ] Resolved mail.mycompany.com as xxx.xxx.xxx.xxx [cache miss]
INFO  [9mzLKQAwcwQ] Connection established to xxx.xxx.xxx.xxx:587
DEBUG [9mzLKQAwcwQ] S: 220 mail.mycompany.com ESMTP
DEBUG [9mzLKQAwcwQ] C: EHLO [127.0.0.1]
DEBUG [9mzLKQAwcwQ] S: 250-mail.mycompany.com
DEBUG [9mzLKQAwcwQ] S: 250-STARTTLS
DEBUG [9mzLKQAwcwQ] S: 250-PIPELINING
DEBUG [9mzLKQAwcwQ] S: 250-8BITMIME
DEBUG [9mzLKQAwcwQ] S: 250-SIZE 23068672
DEBUG [9mzLKQAwcwQ] S: 250 AUTH LOGIN PLAIN CRAM-MD5
DEBUG [9mzLKQAwcwQ] C: STARTTLS
DEBUG [9mzLKQAwcwQ] S: 220 ready for tls
ERROR [9mzLKQAwcwQ] 139673645745984:error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol:../deps/openssl/openssl/ssl/statem/statem_lib.c:1922:
ERROR [9mzLKQAwcwQ]
DEBUG [9mzLKQAwcwQ] Closing connection to the server using "end"
ERROR Send Error: 139673645745984:error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol:../deps/openssl/openssl/ssl/statem/statem_lib.c:1922:
ERROR
[Error: 139673645745984:error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol:../deps/openssl/openssl/ssl/statem/statem_lib.c:1922:
] {
  library: 'SSL routines',
  function: 'ssl_choose_client_version',
  reason: 'unsupported protocol',
  code: 'ESOCKET',
  command: 'CONN'
}
INFO  [9mzLKQAwcwQ] Connection closed
INFO  [9mzLKQAwcwQ] Connection closed

这是我的 SMTP 传输配置:

nodemailer.createTransport({
    host: 'mail.mycompany.com',
    port: 587,
    debug: true,
    logger: true,
    tls: {
      secure: false,
      ignoreTLS: true,
      rejectUnauthorized: false
    },
    auth: {
      user: 'user',
      pass: 'pass'
    }
})

如果我更改为 v11: 11.15.0最新 nodejs版本,一切都会再次运行。 只有在v>1212.1.0发生这种情况,因为我尝试过12.1.012.2.0并遇到了上述相同的错误。

有人在尝试相同的行为? 建议?

注意:正如我在 Q'title 中所说,我已将nodemailer更新到最新版本6.1.1

如果您的邮件服务器仅支持 TLS 1.0,只需添加:

tls: { secureProtocol: "TLSv1_method" }

更新:

我终于找到了我的解决方法 - 很确定你遇到了同样的问题。 从 Node 12 开始失败的原因是 Node Version 12 最终禁用了 TLS 1.0 支持。 不幸的是,我们的测试邮件服务器仅支持 TLS 1.0,因此没有有效的握手选项导致 nodemailer 在握手期间失败。

这也可能与 11.4 版的更改有关,其中 TLS.Min 版本被修改为 TLS 1.2 版 - 请参阅https://nodejs.org/api/tls.html#tls_tls_default_min_version

无论如何,我的修复包括让我的电子邮件服务器使用 TLS 1.0 停止并开始使用 TLS 1.2 或 TLS 1.3。

我在服务器上添加了一堆注册表项并在邮件设置中强制执行 TLS。 我的服务器是 Windows 2008...

1.) 以“管理员”身份打开“RegEdit”(以管理员身份运行)

2.) 导航到以下注册表项

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\

3.) 使用最终的 DWORD 值添加/更新以下每个子键,如图所示:

SSL 2.0\Client   DisabledByDefault : 1
SSL 2.0\Server   DisabledByDefault : 1
SSL 2.0\Server   Enabled : 0

SSL 3.0\Client   DisabledByDefault : 1
SSL 3.0\Server   DisabledByDefault : 1
SSL 3.0\Server   Enabled : 0

TLS 1.0\Server   DisabledByDefault : 0
TLS 1.0\Server   Enabled : 1

TLS 1.2\Client   DisabledByDefault : 0
TLS 1.2\Server   DisabledByDefault : 0
TLS 1.2\Server   Enabled : 1

TLS 1.3\Client   DisabledByDefault : 0
TLS 1.3\Server   DisabledByDefault : 0
TLS 1.3\Server   Enabled : 1

最终应该看起来像这样: https : //support.solarwinds.com/SuccessCenter/s/article/Enable-TLS-1-2-on-Windows-Server-2008

此外,下一个链接在服务器上添加了对大于 1.0 的 TLS 的客户端支持(不需要修复连接到服务器的客户端,但也可能希望将其用于出站连接):

https://support.microsoft.com/en-us/help/3140245/update-to-enable-tls-1-1-and-tls-1-2-as-default-secure-protocols-in-wi

最后,重新启动您的电子邮件服务器,以便启用 TLS,您可以通过检查 TLS 连接来检查注册表设置是否已更正问题 - 我使用了此链接: https : //www.checktls.com/TestReceiver

在我的代码中,我碰巧将我的传输器 tls 部分更新为以下内容,但后来我使用原始设置进行了测试,一切正常-因此问题 100% 与不支持 TLS 1.0 以外的任何其他内容的电子邮件服务器设置有关...

const transporter = nodemailer.createTransport({
  host: 'email.ourhost.com',
  port: 25,
  secure: false,
  auth: {
    user: 'test',
    pass: 'pass'
  },
        tls: {
          rejectUnauthorized: false,
          ignoreTLS: false,
          requireTLS: true
        }
      });

希望能帮到你...

npm 版本 6.9.0、节点版本 12.2.0 和 nodemailer 6.1.1 有同样的问题......碰巧也使用电子邮件的功能测试在升级到节点 12.2.0 时开始失败。 注意:这些测试一直运行良好,直到新版本的 Node ...

这是我们收到的错误(从 mocha 测试结果中提取):

Uncaught AssertionError: expected Object {
  library: 'SSL routines',
  function: 'ssl_choose_client_version',
  reason: 'unsupported protocol',
  code: 'ESOCKET',
  command: 'CONN'
} to be ''

这是我们的传输配置:

const transporter = nodemailer.createTransport({
  host: 'email.ourhost.com',
  port: 25,
  secure: false,
  auth: {
    user: 'test',
    pass: 'pass'
  },
        tls: {
          rejectUnauthorized: false
        }
      });

除了“降级”节点作为解决方案之外,任何有用的建议都将不胜感激!

您可以使用选项--tls-min-v1.0启动node>=12 它对我有用。

我无法使用命令行参数--tls-min-v1更改此设置。 另一种选择是在运行时为所有请求设置最低 TLS 版本。 这可以通过将tls.DEFAULT_MIN_VERSION设置为TLSv1其他内容来完成。 我只是在我所有的require语句之后添加了这个:

tls.DEFAULT_MIN_VERSION = 'TLSv1';

node.js 文档提供了有关此参数的有效选项的更多信息。 https://nodejs.org/docs/latest/api/tls.html#tls_tls_default_min_version

var transporter = nodemailer.createTransport({
    host: "your host address",
    secure: false,
    port: 25,
    auth: {
      user: "your username",
      pass: "your password",
    },
    tls: {
      rejectUnauthorized: false,
      minVersion: 'TLSv1'
    },
  });

似乎这个问题在nodemailer 6.4.0及更高版本上消失了, nodemailerFirebase / Cloud Functions for Firebase环境上的Node.js 12

那是代码:

const mailTransport = nodemailer.createTransport({
  // Make sure the environmental variables have proper typings.
  host: 'MYHOST',
  port: PORT_NUMBER,
  auth: {
    user: 'MY_USER@gmail.com',
    pass: 'MY_PASSWORD',
  },
});
...
exports.myFunction = functions.firestore
  .document(
    'mails/{somethingHere}'
  )
  .onCreate(async (snap: any, context: any) => {
    if (snap.data() === null) return null;
  ...
  return mailTransport
      .sendMail(mailOptions)
      .then((info: string) => {
        console.log('Info: ', info);
      })
      .catch((error: string) => {
        return console.log('Error: ', error); // This log will be shown in Firebase Functions logs.
      });
    ...

环境:

"firebase": "^8.1.1",
"firebase-admin": "^9.4.1",
"firebase-functions": "^3.11.0",
"nodemailer": "^6.4.11",

注意:我已将GMAIL用于我的SMTP设置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM