2017-03-23 17 views
0

我一次發送郵件給多個接收者。我需要一個默認接收者能夠看到他的郵件上的其他接收者的ID。其他接收機在BCC。我試圖通過將默認郵件設置爲to:字段和其他接收器到bcc:。它沒有工作。以下是我的代碼。如何讓一個默認接收者能夠在ActionMailer rails中看到其他接收者的郵件ID

def newequip_matches_wanted 
    @default_mail = "[email protected]" 
    @system_email = SystemEmail.find_by(title: 'Equipment matches WantedEquipment') 
    @subject = @system_email.try(:subject).to_s 
    @subject = "Equipment matches WantedEquipment" if @subject.blank? 
    @equipment = Equipment.last 
    x = Equipment.last.try(:category_id) 
    y = WantedEquipment.pluck(:category_id) 

    a = Equipment.last.try(:sub_category_id) 
    b = WantedEquipment.pluck(:sub_category_id) 
    y.include?(x) && b.include?(a) 
    if true 
     @receiver = WantedEquipment.where(sub_category_id: "#{a}", status: 2).pluck(:email) 
     mail(bcc: @receiver, to: @default_mail, subject: @subject) 
    end 
    end 

我在這裏錯過了什麼? 問題已更新。

+0

第二個應該正常工作,你做了什麼錯誤,你可以ahve一個錯字丟失',''郵件(密件抄送:@接收者,到:@default_mail,主題:@subject)'還有,'@主題'沒有定義 – Sravan

+0

對不起,我會更新我的問題。 '@ default_mail'應該符合'@ receiver'的相同條件。這是行得通的。 '@主題'不是一個問題。我已經在其他地方定義了它。如果'@ default_mail'不符合'@ receiver'的條件,郵件將被髮送到沒有必要的地方。 – user3576036

回答

0

你錯過了主題存入@subject,你也有語法錯誤在第二個代碼mail

def mail 
    @subject = "This is Demo subject" 
    @default_mail = "[email protected]" 
    @receiver = Model.where(status: 2).pluck(:email) 
    mail(bcc: @receiver, to: @default_mail, subject: @subject) 
end 

Here is a reference

+0

我認爲'@ reciever'數組中還包含'@ default_mail'。 – Sravan

相關問題