LoginSignup
6
3

More than 5 years have passed since last update.

ActionMailerでOpenSSL::SSL::SSLErrorを解消

Last updated at Posted at 2016-01-17

事象

RailsでActionMailer、Postfix経由でメールの送信をしようとしたところ、
以下の様なエラーが発生
FATAL -- :
OpenSSL::SSL::SSLError (hostname "localhost" does not match the server certificate):

その時のActionMailerの設定がこちら

config/environments/production.rb
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default_url_options = { :host => 'xxxx.com' }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address => 'localhost'
  }

原因

デフォルトではSMTPサーバにTLSを使って接続しようとするようで、
hostname "localhost"がないと怒られている

解決策

enable_starttls_autoをfalseに設定する

config/environments/production.rb
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default_url_options = { :host => 'xxxx.com' }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address => 'localhost',
    :enable_starttls_auto => false
  }

ちょっとハマりましたが、メールが送れるようになって良かったです。

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3