How do I set the SSL protocol needed for ActionMailer to use a TLS connection?

烈酒焚心 提交于 2020-11-29 03:31:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!