ruby-on-rails – 主机名与服务器证书不匹配 – 无法发送电子邮件

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 主机名与服务器证书不匹配 – 无法发送电子邮件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用Pony邮件发送电子邮件(因为我永远无法让ActionMailer在我的本地 Windows机器上工作).

我的user_mailer.rb文件中的代码包含对Pony.mail方法调用

Pony.mail({
  :to => email_address,:from => 'MyChairSales <support@mychairsales.com>',:subject => subject,:body => email_body,:html_body => html_body,:via => :smtp,:via_options => {
    :address              => 'mail.mychairsales.com',:port                 => '25',:enable_starttls_auto => true,:user_name            => 'mychairs',:password             => 'thepassword',:domain               => "mychairsales.com" # the HELO domain provided by the client to the server
  } 
 })

这是有效的(我已经使用此方法收到了电子邮件),但现在失败了,错误“主机名与服务器证书不匹配”.

这是堆栈跟踪的顶部:

["/usr/lib64/ruby/1.9.3/openssl/ssl-internal.rb:121:in `post_connection_check'","/usr/lib64/ruby/1.9.3/net/smtp.rb:585:in `tlsconnect'","/usr/lib64/ruby/1.9.3
/net/smtp.rb:560:in `do_start'","/usr/lib64/ruby/1.9.3/net/smtp.rb:519:in `start'","/home4/mychairs/ruby/gems/gems/mail-2.4.4/lib/mail/network/delivery_methods
/smtp.rb:144:in `deliver!'","/home4/mychairs/ruby/gems/gems/mail-2.4.4/lib
/mail/message.rb:245:in `deliver!'","/home4/mychairs/ruby/gems/gems/pony-1.4/lib
/pony.rb:166:in `deliver'","/home4/mychairs/ruby/gems/gems/pony-1.4/lib
/pony.rb:138:in `mail'","/home4/mychairs/rails_apps/chairsales/app/mailers
/user_mailer.rb:32:in `send_mail'","/home4/mychairs/rails_apps/chairsales/app/mailers
/user_mailer.rb:23:in `send_password_reset_email'",...

任何指导将不胜感激!

解决方法

有点晚了,但我也遇到了这个错误但是使用了Ruby Mail gem.如果您的SMTP服务器支持TLS,它将尝试使用TLS并验证SSL证书.如果为所使用的主机名颁发证书,或者证书无法通过身份验证(例如,如果它是自签名的并且您不信任CA),那么它将失败,并显示错误“hostname不匹配服务器证书“.

要绕过它,请使用:openssl_verify_mode选项.这可以设置为OpenSSL :: SSL :: VERIFY_NONE以不对证书进行验证 – 它仍将加密SMTP会话.或者OpenSSL库中还有其他可用选项.

使用您的示例,它将是:

Pony.mail({
  :to => email_address,:via_options => {
    :openssl_verify_mode => OpenSSL::SSL::VERIFY_NONE,:address              => 'mail.mychairsales.com',:domain               => "mychairsales.com" # the HELO domain provided by the client to the server
  } 
 })

这也适用于Mail gem.

原文链接:https://www.f2er.com/ruby/267754.html

猜你在找的Ruby相关文章