繁体   English   中英

创建自定义邮件时如何使用Rails邮件程序设置?

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

我正在Rails应用程序中创建一个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对象没有采用Rails设置。

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

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

要使用Rails发送自定义邮件,请阅读此内容。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM