【问题标题】:Openssl issue when sending email through AWS SES通过 AWS SES 发送电子邮件时的 Openssl 问题
【发布时间】:2020-06-11 04:37:27
【问题描述】:

更新: 如果我按照Using the Command Line to Send Email Using the Amazon SES SMTP Interface 的说明进行操作,我可以从我的本地和我的 ec2 实例中完美地发送电子邮件。


我们正在使用 nodemailer 通过 SMTP 发送电子邮件。当我们使用 Gmail 的 SMTP 用户/密码配置所有内容时,一切正常。

我们正在尝试迁移到 AWS SES。一切似乎都设置得很好(域已验证,我们已退出 SANDBOX 模式,并且我们正在使用 SMTP 用户/密码凭据)。

我们使用完全相同的代码,只是在凭证文件中交换了 smtp 用户/密码/主机。使用 SES 凭据发送邮件时,我们收到此错误:

Email was not send due to the following error:  [Error: 62024: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'
}

根据this GitHub issue,问题似乎是:

您要么尝试在非 TLS 端口上使用 TLS,要么尝试在 openssl 您使用的版本与服务器不兼容。

我不太确定如何处理这些信息。我们的 SSL 证书在 ELB 上。

这是负责发送实际电子邮件的代码:

"use strict";

const nodemailer = require("nodemailer");

const transporter = nodemailer.createTransport({
  host: process.env.SMTP_HOST,
  port: process.env.SMTP_PORT,
  secure: process.env.SMTP_SECURE,
  auth: {
    user: process.env.SMTP_AUTH_USER,
    pass: process.env.SMTP_AUTH_PASS
  }
});

module.exports = {
  sendMail: (to, subject, html, callback) => {
    const mailOptions = {
      from: "no-reply@xyz.com",
      to,
      subject,
      html
    };
    transporter.sendMail(mailOptions, (err, info) => {
      if (err) {
        return callback(err);
      }
      return callback(null, info);
    });
  }
};

【问题讨论】:

  • 我知道已经有一段时间了,但是你使用的是什么端口?我在使用端口 587 时遇到了同样的问题 - 更改为端口 465 解决了问题。

标签: node.js openssl smtp amazon-ses nodemailer


【解决方案1】:

TLDR;

secure 选项为true 时使用端口465。

我做了什么

我在这个问题上去了the comment@moulder,它奏效了。

需要明确的是,您应该使用 465,true 来使用 SSL 进行连接,或者 587,false 来不使用 SSL 进行连接并通过 STARTTLS 进行升级。任何其他组合都行不通。代码有问题,在这里修复它:

来源:Fabien Potenciersymfony/symfony#34846

另见symfony/symfony/34067

亚马逊怎么说

就像有 HTTP 和 HTTPS(“s”表示安全),也有 SMTP 和 SMTPS(有点)......至于通信的安全版本,有多种方法可以建立这种安全性。

  • STARTTLS - 客户端连接没有安全性。服务器说它支持安全性。然后,客户端与 SMTP 服务器协商安全合同,并从不安全通信迁移到安全通信。
  • TLS Wrapper - 客户端从一开始就是安全的。

来源:Amazon SES Docs - Connecting to an SMTP endpoint

【讨论】:

    猜你喜欢
    • 2016-11-17
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 2018-07-18
    • 1970-01-01
    • 2015-12-13
    • 2019-03-23
    • 1970-01-01
    相关资源
    最近更新 更多