问题
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.
Here is my configuration:
config.action_mailer.smtp_settings = {
address: 'address.domain',
port: 587,
user_name: 'UNAME',
password: 'PWD',
authentication: :login,
tls: true,
enable_starttls_auto: true
}
To ensure I am using the latest openssl version, I have also required 'openssl' in my Gemfile, and it installed openssl-2.1.2.
Suggestions on next steps?
回答1:
port: 587,
...
tls: true,
enable_starttls_auto: true
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.
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.
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.
来源:https://stackoverflow.com/questions/59687194/how-do-i-set-the-ssl-protocol-needed-for-actionmailer-to-use-a-tls-connection