2010/11/09

Rails3 のメール送信で "hostname was not match with the server certificate" というエラーが出た場合には

Rails3.0.1 にてメール送信のテストをしているとこんなエラーがでた。
/usr/lib/ruby/gems/1.8/gems/railties-3.0.1/lib/rails/commands/runner.rb:50: /usr/lib/ruby/1.8/openssl/ssl.rb:123:in `post_connection_check': hostname was not match with the server certificate (OpenSSL::SSL::SSLError)
        from /usr/lib/ruby/1.8/net/smtp.rb:582:in `tlsconnect'
        from /usr/lib/ruby/1.8/net/smtp.rb:562:in `do_start'
        from /usr/lib/ruby/1.8/net/smtp.rb:525:in `start'
        from /usr/lib/ruby/gems/1.8/gems/mail-2.2.9/lib/mail/network/delivery_methods/smtp.rb:115:in `deliver!'
        from /usr/lib/ruby/gems/1.8/gems/mail-2.2.9/lib/mail/message.rb:1928:in `do_delivery'
        from /usr/lib/ruby/gems/1.8/gems/mail-2.2.9/lib/mail/message.rb:228:in `deliver'
        from /usr/lib/ruby/gems/1.8/gems/actionmailer-3.0.1/lib/action_mailer/base.rb:401:in `deliver_mail'
        from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/notifications.rb:52:in `instrument'
        from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
        from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/notifications.rb:52:in `instrument'
        from /usr/lib/ruby/gems/1.8/gems/actionmailer-3.0.1/lib/action_mailer/base.rb:399:in `deliver_mail'
        from /usr/lib/ruby/gems/1.8/gems/mail-2.2.9/lib/mail/message.rb:228:in `deliver'
        from (eval):1
        from /usr/lib/ruby/gems/1.8/gems/railties-3.0.1/lib/rails/commands.rb:39:in `eval'
        from /usr/lib/ruby/gems/1.8/gems/railties-3.0.1/lib/rails/commands/runner.rb:50
        from /usr/lib/ruby/gems/1.8/gems/railties-3.0.1/lib/rails/commands.rb:39:in `require'
        from /usr/lib/ruby/gems/1.8/gems/railties-3.0.1/lib/rails/commands.rb:39
        from script/rails:6:in `require'
        from script/rails:6
TLS接続を使用としてエラーになっているみたいなので、TLS接続をしないようにすればいいらしい。(今の環境はPOP before SMTPなのでTLSは必要ない)
config/application.rb にて smtp_settings に設定を追加すればメール送信できた。
config.action_mailer.smtp_settings = {
  :enable_starttls_auto => false, # ←これ
  :address => 'example.com',
  :port => 587,
  :domain => 'localhost',
  :user_name => 'user',
  :password => 'password'
}

0 件のコメント :

コメントを投稿