创建自定义邮件时,如何使用Rails Mailer设置



我正在在铁路应用中创建一个Mail对象,并希望它选择邮件器设置:

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

显然自定义Mail对象没有拾取导轨设置。

查看代码,我们可以以以下方式从邮件中获取配置:

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

使用导轨发送自定义邮件,请阅读此。

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

最新更新