2013-02-06 41 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! 

但仍。感謝您的支持!

相關問題