【问题标题】:unsupported protocol (OpenSSL::SSL::SSLError) error when sending mail with ActionMailer in Ubuntu 20.04在 Ubuntu 20.04 中使用 ActionMailer 发送邮件时出现不支持的协议 (OpenSSL::SSL::SSLError) 错误
【发布时间】:2020-06-26 09:41:09
【问题描述】:

我刚刚安装了一个 Ubuntu 20.04 服务器并且我已经安装了 redmine,但是启用了 ssl 的邮件发送不起作用。

所以我开始了一些使用 ruby​​ 发送电子邮件的测试。

我看到了一种发送邮件in this post 的方法,所以我尝试用脚本和相关的mailer/daily_email.text.erb 做同样的事情:

ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.logger = Logger.new (STDOUT)
ActionMailer::Base.logger.level = 记录器::DEBUG
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :address => "smtps.aruba.it",
  :端口=> 465,
  :domain => "mydomain.it",
  :authentication => :login,
  :user_name => "redmine@mydomain.it",
  :password => "我的密码",
  :enable_starttls_auto => 真,
  :ssl => 真
}

ActionMailer::Base.view_paths= File.dirname(__FILE__)

类 Mailer “myuser@mydomain.it”,
            :from => "redmine@mydomain.it",
            :subject => "测试邮件") 做 |format|
              格式.文本
              格式.html
    结尾
  结尾
结尾

电子邮件 = Mailer.daily_email
发送电子邮件
email.deliver
这是一封短信

这是一个变量 

这是脚本的输出

rmadmin@redmineserver:~/scripts$ ruby test_mail.rb
D, [2020-06-26T08:59:34.798706 #1340] DEBUG -- : Mailer#daily_email: processed outbound mail in 1396.4ms
Date: Fri, 26 Jun 2020 08:59:34 +0000
From: redmine@mydomain.it
To: myuser@mydomain.it
Message-ID: <5ef5b8f6c48f6_53c208-492@redmineserver.mail>
Subject: testing mail
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

This is a text email

and this is a variable var
I, [2020-06-26T08:59:39.961850 #1340]  INFO -- : Delivered mail 5ef5b8f6c48f6_53c208-492@uburedmine.mail (5152.0ms)
D, [2020-06-26T08:59:39.962362 #1340] DEBUG -- : Date: Fri, 26 Jun 2020 08:59:34 +0000
From: redmine@mydomain.it
To: myuser@mydomain.it
Message-ID: <5ef5b8f6c48f6_53c208-492@uburedmine.mail>
Subject: testing mail
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

This is a text email

and this is a variable var

Traceback (most recent call last):
        16: from test_mail.rb:36:in `<main>'
        15: from /usr/lib/ruby/2.7.0/delegate.rb:83:in `method_missing'
        14: from /var/lib/gems/2.7.0/gems/mail-2.7.1/lib/mail/message.rb:260:in `deliver'
        13: from /var/lib/gems/2.7.0/gems/actionmailer-6.0.3.2/lib/action_mailer/base.rb:587:in `deliver_mail'
        12: from /var/lib/gems/2.7.0/gems/activesupport-6.0.3.2/lib/active_support/notifications.rb:180:in `instrument'
        11: from /var/lib/gems/2.7.0/gems/activesupport-6.0.3.2/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
        10: from /var/lib/gems/2.7.0/gems/activesupport-6.0.3.2/lib/active_support/notifications.rb:180:in `block in instrument'
         9: from /var/lib/gems/2.7.0/gems/actionmailer-6.0.3.2/lib/action_mailer/base.rb:589:in `block in deliver_mail'
         8: from /var/lib/gems/2.7.0/gems/mail-2.7.1/lib/mail/message.rb:260:in `block in deliver'
         7: from /var/lib/gems/2.7.0/gems/mail-2.7.1/lib/mail/message.rb:2159:in `do_delivery'
         6: from /var/lib/gems/2.7.0/gems/mail-2.7.1/lib/mail/network/delivery_methods/smtp.rb:100:in `deliver!'
         5: from /var/lib/gems/2.7.0/gems/mail-2.7.1/lib/mail/network/delivery_methods/smtp.rb:109:in `start_smtp_session'
         4: from /usr/lib/ruby/2.7.0/net/smtp.rb:518:in `start'
         3: from /usr/lib/ruby/2.7.0/net/smtp.rb:552:in `do_start'
         2: from /usr/lib/ruby/2.7.0/net/smtp.rb:584:in `tlsconnect'
         1: from /usr/lib/ruby/2.7.0/net/protocol.rb:44:in `ssl_socket_connect'
/usr/lib/ruby/2.7.0/net/protocol.rb:44:in `connect_nonblock': SSL_connect returned=1 errno=0 state=error: unsupported protocol (OpenSSL::SSL::SSLError)

我已经在电子邮件客户端中尝试了 smtp 参数并且它们有效。

我正在从旧的 Ubuntu 16.04 服务器上的 redmine 安装迁移,在该服务器上可以发送邮件。

我尝试了许多配置变体,但均未成功。我开始认为 Ubuntu 20.04 和 Ubuntu 16.04 使用的 openssl 版本有所不同,但我无法检查这些信息的位置以及是否可以告诉 ActionMailer 使用不同版本的 ssl。

有些答案,例如this one 不适用,因为太旧了。

这是openssl version -a的输出

OpenSSL 1.1.1f  31 Mar 2020
built on: Mon Apr 20 11:53:50 2020 UTC
platform: debian-amd64
options:  bn(64,64) rc4(16x,int) des(int) blowfish(ptr)
compiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -Wa,--noexecstack -g -O2 -fdebug-prefix-map=/build/openssl-P_ODHM/openssl-1.1.1f=. -fstack-protector-strong -Wformat -Werror=format-security -DOPENSSL_TLS_SECURITY_LEVEL=2 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAESNI_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPOLY1305_ASM -DNDEBUG -Wdate-time -D_FORTIFY_SOURCE=2
OPENSSLDIR: "/usr/lib/ssl"
ENGINESDIR: "/usr/lib/x86_64-linux-gnu/engines-1.1"
Seeding source: os-specific

我也试过modify the openssl configuration,没有结果。

我应该怎么做才能在 Ubuntu 20.04 上解决 ruby​​ 上的这个 ssl 问题?

【问题讨论】:

    标签: ruby email openssl actionmailer ubuntu-20.04


    【解决方案1】:

    引用libssl1.1 软件包的 NEWS.Debian 条目,该软件包在 Ubuntu 20.04 中提供了大部分 openssl 核心。您可以在系统上的/usr/share/doc/libssl1.1/NEWS.Debian 找到它。

    TLS 连接的默认安全级别从 级别 1 到级别 2。这从 80 位安全级别移动到 112 位安全级别,需要 2048 位或更大的 RSA 和 DHE 密钥、224 位或更大的 ECC 密钥、SHA-2、TLSv1.2 或 DTLSv1.2。

    可以在/etc/ssl/openssl.cnf 中更改系统范围的设置。 应用程序也可能有办法覆盖默认值。

    在默认/etc/ssl/openssl.cnf中可以添加section来指定 CipherStringCipherString 可用于设置安全性 等级。有关安全级别的信息可以在 SSL_CTX_set_security_level(3ssl) 联机帮助页。其他信息可以 在ciphers(1ssl)config(5ssl) 中找到。

    /etc/ssl/openssl.cnf 中的默认值改回以前的 系统范围的默认值可以通过在文件顶部添加:

    # System default
    openssl_conf = default_conf
    

    并在文件底部添加:

    [default_conf]
    ssl_conf = ssl_sect
    
    [ssl_sect]
    system_default = system_default_sect
    
    [system_default_sect]
    CipherString = DEFAULT:@SECLEVEL=1
    

    建议您联系远程站点,以防万一 默认值会导致问题。

    在您的情况下,这正是问题所在:您的邮件提供商显然在他们的邮件服务器上还不支持 TLS 1.2(或 TLS 1.3),这导致连接强制执行此安全级别(如 Ubuntu 20.04 中的默认设置)到失败。

    在短期内,如果您可以接受不太安全的配置,则可以遵循 NEWS 条目中的建议。但是,您还应该联系您的邮件提供商并要求他们更新他们的服务器配置(可能还有他们的软件),以便他们支持更新的 TLS 协议,而不仅仅是过时且不安全的 TLSv1.0。

    【讨论】:

      猜你喜欢
      • 2012-04-23
      • 2012-08-30
      • 1970-01-01
      • 2020-11-07
      • 1970-01-01
      • 1970-01-01
      • 2018-05-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多