nulltek
nulltek

Reputation: 3337

rails actionmailer multiple recepients

In my Rails app I want to use ActionMailer to send emails to multiple recipients. Below is the code I've written that works with a single attribute:

 def new_call(medic, call)
    @call = call
    @medic = medic

    mail to: @medic.medic_email, subject: "New Call: #{@call.incident_number}"
  end 

I want to include @medic.medic_sms to send the message to their phones. I tried the following code but it doesn't work.

 def new_call(medic, call)
    @call = call
    @medic = medic

    mail to: @medic.medic_email, @medic.medic_sms, subject: "New Call: #{@call.incident_number}"
  end

Can someone suggest how to add the second attribute cleanly so it works?

Thanks in advance.

Upvotes: 0

Views: 428

Answers (2)

nulltek
nulltek

Reputation: 3337

Putting the two attributes into an array solved the problem.

[@medic.medic_email, @medic.medic_sms]

Upvotes: 1

user229044
user229044

Reputation: 239220

You have a syntax error. If you want to pass an array to to:, you need to explicitly wrap it in []:

mail to: [@medic.medic_email, @medic.medic_sms], subject: ...

See ActionMailer Basics section 2.3.4: Sending Email To Multiple Recipients.

Upvotes: 0

Related Questions