简体   繁体   English

向多个收件人发送电子邮件

[英]send emails to multiple recipients actionmailer

I have in invitation_mailer.rb the next: 我在Invitation_mailer.rb中有下一个:

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: @ invitation.recipients是一个包含以下电子邮件的数组:

 ["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("; ") 尝试@invitations.recipients.join("; ")

You are trying to call :recipients on a String-object in your array, which cannot work. 您试图在数组中的String对象上调用:recipients,但无法正常工作。

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. map(&:recipients)意思是:在数组中的每个元素上调用#recipients方法。 You get he error since your array holds strings, and clearly String doesn't have method #recipients :) 因为数组包含字符串,所以很容易出错,并且很明显,String没有方法#recipients :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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