无法连接到AWS SES SMTP终端节点

时间:2020-08-29 16:01:27

标签: node.js amazon-web-services email ssl

我正在构建一个应用程序,该应用程序将使用AWS SES通过SMTP发送电子邮件。我已经正确配置了一个域,并确认可以使用AWS开发工具包从该域发送电子邮件。我已创建SMTP凭据,并确保已使用正确的权限正确配置IAM用户。我编写了一个使用Nodemailer发送电子邮件的测试脚本。

使用我的个人开发计算机在家庭网络上可以成功运行测试脚本,但是当在我的家庭网络上使用由我的公司客户端发行的开发笔记本电脑时,该脚本将无法运行。企业笔记本电脑运行许多安全工具,包括ZScaler。我还知道,由于ZScaler服务,必须将NPM设置为使用自签名证书(命令为npm config set cafile {CA_FILEPATH})。

我不知道为什么该脚本不能在公司的笔记本电脑上运行,并且希望在确定下一步尝试时会有所帮助。

这是脚本:

'use strict';

const nodemailer = require('nodemailer');

const runtest = async function() {
    console.debug('Creating the SMTP transport');
    const transporter = nodemailer.createTransport({
      host: 'email-smtp.us-west-2.amazonaws.com',
      port: 465,
      secure: true,
      auth: {
        user: 'myusername',
        pass: 'mypassword',
      },
    });

    console.debug('Building mail options');
    const mailOptions = {
      from: 'me@example.com',
      to: 'you@example.com',
      subject: 'subject',
      text: 'body',
      html: '<h1>Hi</h1',
    };

    console.debug('Sending mail...');
    const info = await transporter.sendMail(mailOptions);
    console.debug(`Sent mail.  Info: ${JSON.stringify(info, null, 2)}`);
    console.info('Message sent!');
};
runtest().catch(console.error);

从企业笔记本电脑运行时,结果如下:

Creating the SMTP transport
Building mail options
Sending mail...
Error: read ECONNRESET
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:200:27) {
  errno: 'ECONNRESET',
  code: 'ESOCKET',
  syscall: 'read',
  command: 'CONN'
}

我尝试过的事情:

  • 使用TLS设置(例如rejectUnauthorized: false并指定TLS版本
  • 连接到公司VPN或从公司VPN断开
  • 我在this Github issue上找到了一个参考,该参考建议测试与openssl的连接。我运行了此命令openssl s_client -connect email-smtp.us-west-2.amazonaws.com:465,这就是结果(看起来还可以):
CONNECTED(0000021C)
write:errno=10054
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 336 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---

1 个答案:

答案 0 :(得分:0)

就我而言,是导致此错误的节点版本。我已将节点版本升级到v12.x,以解决此问题。