hyperrjas
hyperrjas

Reputation: 10744

send emails to multiple recipients actionmailer

I have in invitation_mailer.rb the next:

class InvitationMailer < ActionMailer::Base
  default :from => "[email protected]"
  def invitation_friends(invitation, user)
   @user = user
   @invitation = invitation
   mail(:bcc => @invitation.recipients.map(&:recipients), :subject => "Subject email")
  end
end

@invitation.recipients is an array with emails like:

 ["[email protected]","[email protected]"]

but I get in log the next:

NoMethodError (undefined method `recipients' for "[email protected]":String):

What am I doing wrong?

Thank you!

Upvotes: 1

Views: 5574

Answers (2)

Vlad Khomich
Vlad Khomich

Reputation: 5880

I believe this line:

@invitation.recipients.map(&:recipients)

should actually be:

@invitation.recipients.join(';')

map(&:recipients) means: call #recipients method on each element in the array. You get he error since your array holds strings, and clearly String doesn't have method #recipients :)

Upvotes: 1

macsniper
macsniper

Reputation: 330

Try @invitations.recipients.join("; ")

You are trying to call :recipients on a String-object in your array, which cannot work.

Upvotes: 5

Related Questions