ruby-on-rails-3 – 在运行时在rails中切换邮件传递方法
发布时间:2020-12-16 22:42:00 所属栏目:百科 来源:网络整理
导读:我正在设置一个rails应用程序,以便我可以根据某些条件是否为真,选择不同的邮件传递方式. 所以,给出两种交付方式: ActionMailer::Base.add_delivery_method :fooActionMailer::Base.add_delivery_method :bar 我以为我可以创建一个电子邮件拦截器来做这样的
我正在设置一个rails应用程序,以便我可以根据某些条件是否为真,选择不同的邮件传递方式.
所以,给出两种交付方式: ActionMailer::Base.add_delivery_method :foo ActionMailer::Base.add_delivery_method :bar 我以为我可以创建一个电子邮件拦截器来做这样的事情: class DeliveryMethodChooser def self.delivering_email(message) if some_condition # code to use mail delivery method foo else # code to use mail delivery method bar end end end 问题是,我不知道如何实际设置更改邮件传递方式用于给定消息.有任何想法吗?甚至可以动态选择要使用的delivery_method? 解决方法
您也可以将:delivery_method选项传递给邮件方法:
def notification mail(:from => 'from@example.com',:to => 'to@example.com',:subject => 'Subject',:delivery_method => some_condition ? :foo : :bar) end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |