简体   繁体   中英

send emails to multiple recipients actionmailer

I have in invitation_mailer.rb the next:

class InvitationMailer < ActionMailer::Base
  default :from => "email@email.com"
  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:

 ["email1@example.com","email2@example.com"]

but I get in log the next:

NoMethodError (undefined method `recipients' for "email1@example.com":String):

What am I doing wrong?

Thank you!

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

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

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM