2013-02-06 39 views
4

我有必要这么做,因为它似乎是合乎逻辑对我说:Rails的发送2个不同的电子邮件从一个邮件功能

def notification(vehicle) 
    @vehicle = vehicle 

    mail(:to => @vehicle.owner.email_address, :template_name => "n_o") 
    mail(:to => @vehicle.booker.email_address, :template_name => "n_b") 

的问题是:我只接受最后电子邮件。因此,在我上面的示例中,只有预订者会收到电子邮件,并且没有任何内容正在发送给所有者。

什么问题?如何解决它?我应该创建两个独立的邮件功能,例如notification_owner(vehicle)和notification_booker(vehicle),还是有一个简单的解决方案?

谢谢!

+0

检查此问题http://stackoverflow.com/questions/7437270/send-to-multiple-recipients-in-rails-with-actionmailer –

+2

谢谢。但这不完全是我在这里 – Dmitri

回答

0

尝试:

def notification(vehicle,template_name) 
    @vehicle = vehicle 
    mail(:to => @vehicle.owner.email_address, :template_name => template_name) 
end 


Mailer.notification(@vehicle,"n_o").deliver 
Mailer.notification(@vehicle,"n_b").deliver 
+0

为什么我会有相同的模板?这些电子邮件的内容对于所有者和预订者而言是不同的。 – Dmitri

+0

更新了答案 – shweta

+0

行。我明白了。会试试看。 – Dmitri

1

确定。所以,傻了,我忘了提及我正在处理delayed_jobs创业板。所以,问题是,我忘了指定“.deliver!”每个“邮件”功能之后的动作。

因此,它应该是这样的:

mail(:to => @vehicle.owner.email_address, :template_name => "n_o").deliver! 
mail(:to => @vehicle.booker.email_address, :template_name => "n_b").deliver! 

但仍。感谢您的支持!

相关问题