繁体   English   中英

在 Ubuntu 20.04 中使用 ActionMailer 发送邮件时出现不受支持的协议 (OpenSSL::SSL::SSLError) 错误

[英]unsupported protocol (OpenSSL::SSL::SSLError) error when sending mail with ActionMailer in Ubuntu 20.04

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

所以我已经开始了一些测试来发送 email 和 ruby。

在这篇文章中看到了一种发送邮件的方法,所以我尝试使用脚本和相关的mailer/daily_email.text.erb做同样的事情:

ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.logger = Logger.new (STDOUT)
ActionMailer::Base.logger.level = Logger::DEBUG
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :address   => "smtps.aruba.it",
  :port      => 465,
  :domain    => "mydomain.it",
  :authentication => :login,
  :user_name      => "redmine@mydomain.it",
  :password       => "mypassword",
  :enable_starttls_auto => true,
  :ssl => true
}

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

class Mailer < ActionMailer::Base

  def daily_email
    @var = "var"

    mail(   :to      => "myuser@mydomain.it",
            :from    => "redmine@mydomain.it",
            :subject => "testing mail") do |format|
              format.text
              format.html
    end
  end
end

email = Mailer.daily_email
puts email
email.deliver
This is a text email

and this is a variable <%= @var %>

这是脚本的 output

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)

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

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

我已经尝试了许多配置变体但没有成功。 I'm starting to think that there's a difference in the openssl version used by Ubuntu 20.04 and Ubuntu 16.04, but I'm not able to check where this information is and if I can tell ActionMailer to use a different version of ssl.

有些答案,比如这个答案,因为太旧而不适用。

这是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

我还尝试修改 openssl 配置,但没有结果。

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

To quote the NEWS.Debian entry of the libssl1.1 package which ships most of the openssl core in Ubuntu 20.04. 您可以在系统上的/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中,可以添加部分来指定CipherString CipherString可用于设置安全级别。 有关安全级别的信息可以在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。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM