The host name does not match the server certificate - cannot send email

I use Pony mail to send emails (because I could never get ActionMailer to work in a local Windows window).

The code in user_mailer.rb includes this call to the Pony.mail method:

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 } }) 

This worked (I received an email using this method), but now with the error "hostname does not match server certificate".

Here is the top of the stack trace:

 ["/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'",... 

Any guidance would be greatly appreciated!

+6
source share
1 answer

A bit late, but I also ran into this error, but with a Ruby Mail stone. If your SMTP server supports TLS, it will try to use TLS and authenticate with the SSL certificate. If the certificate is issued for a host name other than that used, or if the certificate cannot be authenticated (for example, if it is signed and you do not trust the CA), then it will fail with the error "host name does not match server certificate".

To get around this, use the parameter: openssl_verify_mode. This can be set in OpenSSL :: SSL :: VERIFY_NONE to not verify the certificate - it will still encrypt the SMTP session. Or there are other options available in the OpenSSL library.

Using your example, this will be:

 Pony.mail({ :to => email_address, :from => 'MyChairSales < support@mychairsales.com >', :subject => subject, :body => email_body, :html_body => html_body, :via => :smtp, :via_options => { :openssl_verify_mode => OpenSSL::SSL::VERIFY_NONE, :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 } }) 

This also works with zip stone.

+17
source

All Articles