Dmytrii Nagirniak
Dmytrii Nagirniak

Reputation: 24088

How to use Rails mailer settings when creating a custom Mail?

I'm creating a Mail object in a Rails app and want it to pick the mailer settings:

original = UserMailer.new_registration
original.deliver# Does the job

custom = Mail.new(original.to_s)
custom.deliver # Fails: OpenSSL::SSL::SSLError: hostname does not match the server certificate

Apparently the custom Mail object isn't picking up the Rails settings.

Upvotes: 0

Views: 1235

Answers (2)

Dmytrii Nagirniak
Dmytrii Nagirniak

Reputation: 24088

Looking at the code, we can pick up the config from the mailer the following way:

custom = ::Mail.new(raw_email)
key = Rails.application.config.action_mailer.delivery_method
delivery_method = ActionMailer::Base.delivery_methods.fetch(key)
delivery_settings = ActionMailer::Base.send("#{key}_settings")
custom.delivery_method(delivery_method, delivery_settings)
custom.deliver

Upvotes: 4

vijikumar
vijikumar

Reputation: 1815

To send custom mails using rails please read this.

http://mdushyanth.wordpress.com/2011/08/06/custom-mail-delivery-method-in-rails-3/

Upvotes: 0

Related Questions