I keep getting the below error every time an email is sent. After some research, I found that the error is from not being able to set the ca_file or ca_path attribute for OpenSSL::SSL::SSLContext through the mail plugin (gem) which is used by action mailer. My proofs are in "mail-2.4.4/lib/mail/network/delivery_methods/smtp.rb" at line 122 and at
https://github.com/mikel/mail/issues/345. So, I created a monkey patch, "config/initializers/mail.rb", to set a default ca_file or ca_path. Does anyone have a better solution keeping security in mind? Is this actually the problem? Did I make any mistakes in my patch?
Monkey patch file name: "config/initializers/mail.rb"
Net::SMTP.class_eval do
def SMTP.default_ssl_context
context = OpenSSL::SSL::SSLContext.new
context.ca_file = '/path/to/ca-file'
context
end
end
ErrorOpenSSL::SSL::SSLError (hostname was not match with the server certificate):
app/models/polymorphic/comment.rb:63:in `block in notify_subscribers'
app/models/polymorphic/comment.rb:59:in `eacch'
app/models/polymorphic/comment.rb:59:in `notify_subscribers'
app/controllers/comments_controller.rb:88:in `create'
Rendered vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (6.0ms)
Rendered vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.8ms)
Rendered vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (20.1ms)