使用ActionMailer发送到Rails中的多个收件人 [英] Send to multiple recipients in Rails with ActionMailer
问题描述
我正在尝试根据数据库中的布尔值发送多封电子邮件。该应用程序是一个简单的计划应用程序,用户可以将其班次标记为 replacement_needed,这会将电子邮件发送给所有要求接收这些电子邮件的用户。麻烦的是,似乎每个人都只能发送一封电子邮件。这是我当前的代码:
def request_replacement(shift)
@shift =移位
@user = shift .user
@recipients = User.where(:replacement_emails => true)。所有
@url = root_url
@ recipients.each | r |
@name = r.fname
mail(:to => r.email,
:subject =>已请求替换文员)
结束
end
我遇到了同样的问题。 。dunno这是什么交易。.我回避了它:
而不是打电话
Mailer.request_replacement(shift)。从我的控制器传递
我要在邮件程序上定义一个类方法,然后调用它。然后,该方法将遍历列表并调用传递 n次……似乎可行
class Mailer
def self.send_replacement_request(shift)
@收件人= ...
@ recipients.each做|收件人|
request_replacement(收件人,班次)。交付
结束
结束
def request_replacement(收件人,班次)
...
邮件( ...)
结束
结束
并从控制器中调用
Mailer.send_replacement_request(shift)
I'm trying to send multiple emails based on a boolean value in my database. The app is a simple scheduling app and user can mark their shift as "replacement_needed" and this should send out emails to all the users who've requested to receive these emails. Trouble is, it only every seems to send to one email. Here's my current code:
def request_replacement(shift)
@shift = shift
@user = shift.user
@recipients = User.where(:replacement_emails => true).all
@url = root_url
@recipients.each do |r|
@name = r.fname
mail(:to => r.email,
:subject => "A replacement clerk has been requested")
end
end
i'm having this same problem.. dunno what the deal is.. I sidestep it by:
instead of calling
Mailer.request_replacement(shift).deliver
from my controller,
I'd define a class method on the mailer, and call that. That method would then iterate through the list and call deliver "n" times... that seems to work
class Mailer
def self.send_replacement_request(shift)
@recipients = ...
@recipients.each do |recipient|
request_replacement(recipient, shift).deliver
end
end
def request_replacement(recipient, shift)
...
mail(...)
end
end
and from the controller, call
Mailer.send_replacement_request(shift)
这篇关于使用ActionMailer发送到Rails中的多个收件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!