Reputation: 3471
I have a controller action that creates a reminder, I'm passing @event
and @users
to go through the users and check if they have checked the check box for reminder, by default I have set it to True.
This is suppose to check for me which user wants to get an email, and send them the email in the mailer, however it doesn't work that way. It clear the queue without sending the email.
def create
ReminderMailer.delay(queue: "#{@event.name}_letter", run_at: 1.minutes.from_now).events_reminder(@event,@users)
end
In my mailer I have this:
def events_reminder(event,users)
@event = event
@users = users
users.each do |user|
if user.eventReminder == true
mail to: user.email, subject: "Reminder"
end
end
end
It creates the queue, but it doesn't send the emails.
Am I facing the problem that this user is getting ?
Rails 3 + action mailer - Cannot loop to send emails
Upvotes: 0
Views: 203
Reputation: 3471
After 7 days :/! Found the solution in the documentation... It's true when they say RTFM :)!
Here is the solution:
2.3.3 Sending Email To Multiple Recipients
It is possible to send email to one or more recipients in one email (e.g., informing all admins of a new signup) by setting the list of emails to the :to key. The list of emails can be an array of email addresses or a single string with the addresses separated by commas.
class AdminMailer < ActionMailer::Base
default to: Proc.new { Admin.pluck(:email) },
from: '[email protected]'
def new_registration(user)
@user = user
mail(subject: "New User Signup: #{@user.email}")
end
end
http://edgeguides.rubyonrails.org/action_mailer_basics.html#action-mailer-callbacks
Upvotes: 0