如何设置 ActionMailer 使用 TLS 连接所需的 SSL 协议? [英] How do I set the SSL protocol needed for ActionMailer to use a TLS connection?

查看:21
本文介绍了如何设置 ActionMailer 使用 TLS 连接所需的 SSL 协议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am running into an issue trying to use my campus's SMTP server with my Rails 5.x app. I receive the following error: 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.

To ensure I am using the latest openssl version, I have also required 'openssl' in my Gemfile, and it installed openssl-2.1.2.

对下一步的建议?

推荐答案

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

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

According to the documentation ":ssl/:tls - Enables the SMTP connection to use SMTP/TLS (SMTPS: SMTP over direct TLS connection)". But port 587 is not for direct TLS but for TLS upgrade via the STARTTLS command. Direct TLS is done on port 465 instead if enabled.

因此,您的客户端尝试使用 TLS 访问非 TLS 连接,这导致了这个奇怪的错误.另请参阅我对类似问题的解释,其中 Perl 而不是 Ruby.

Thus, your client tries to access a non-TLS connection with TLS and this results in this strange error. See also my explanation on a similar question where this happened with Perl not Ruby.

要解决此问题,请使用带有 tls 的端口 465(如果在服务器上启用)或使用端口 587 并依赖 enable_starttls_auto 它将稍后升级到TLS.

To solve the problem either use port 465 with tls (if enabled on the server) or use port 587 and rely on enable_starttls_auto that it will do a later upgrade to TLS.

这篇关于如何设置 ActionMailer 使用 TLS 连接所需的 SSL 协议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆