ruby-on-rails - 如何设置 ActionMailer 使用 TLS 连接所需的 SSL 协议(protocol)?

标签 ruby-on-rails ssl actionmailer

我在尝试将校园的 SMTP 服务器与我的 Rails 5.x 应用程序一起使用时遇到问题。我收到以下错误:SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol。

这是我的配置:

config.action_mailer.smtp_settings = {
    address:              'address.domain',
    port:                 587,
    user_name:            'UNAME',
    password:             'PWD',
    authentication:       :login,
    tls:                  true,
    enable_starttls_auto: true
  }

为确保我使用的是最新的 openssl 版本,我还在我的 Gemfile 中要求“openssl”,并且它安装了 openssl-2.1.2。

关于后续步骤的建议?

最佳答案

port:                 587,
...
tls:                  true,
enable_starttls_auto: true

根据 the documentation “:ssl/:tls - 启用 SMTP 连接以使用 SMTP/TLS(SMTPS:通过直接 TLS 连接的 SMTP)”。但端口 587 不是用于直接 TLS,而是用于通过 STARTTLS 命令进行 TLS 升级。如果启用,直接 TLS 将在端口 465 上完成。

因此,您的客户端尝试使用 TLS 访问非 TLS 连接,这导致了这个奇怪的错误。另见 my explanation on a similar question这发生在 Perl 而不是 Ruby 上。

要解决此问题,请将端口 465 与 tls(如果在服务器上启用)一起使用,或者使用端口 587 并依赖于稍后升级到的 enable_starttls_auto TLS。

关于ruby-on-rails - 如何设置 ActionMailer 使用 TLS 连接所需的 SSL 协议(protocol)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59687194/

相关文章:

ruby-on-rails - Firefox不支持HTTP “Content-Type” “application/octet-stream”

node.js - 如何将 SSL 证书 (ca-cert) 添加到 node.js 环境变量以连接到 Digital Ocean Postgres 托管数据库?

Java 8 如何确保我们的代码检查完整的证书链?

ruby-on-rails-3 - 自定义辅助方法上的 "undefined method"

ruby-on-rails-3 - ActionMailer 的未定义方法 `before_action'

ruby-on-rails - 在Rails中,为什么仅在测试中我的邮件正文为空?

html - 用于缩放的响应式图像高度和宽度百分比?

ruby-on-rails - 我应该在 Ruby on Rails 3.0 中的计数器缓存列上添加索引吗

ruby-on-rails - Rails 6 - 尽管添加了 rails/ujs,但破坏了 GET 路径

java - Android 客户端通过 SSL 连接到服务器