We are building a rails application that’s sort of a CRM + room/course
booking. Among other things, it provides a centralized database of all
the people the company has been in contact with.
We want to provide the possibility of sending customized email messages
to groups of contacts, for example a newsletter to 500 people starting
with “Hi [:name:]”. The naive approach we’re using is basically placing
the following code in the controller:
email.people.each do |p|
This generates a custom email for that person, with fields such as
filled with the person’s name
raw_email = PeopleMailer.create_general_email(email, p, sent_at)
rescue Exception => e
email.log += “\n” + format_time(Time.now) + “\n” + e.message + “\n”
The problem is that generating the 500 individual emails takes a
significant amount of time, which causes the browser to time out. What
we want, is to give the user a response immidiately, and then process
the sending of the email in the background.
How to go about this? I’ve seen the note about mass mailing on
but I couldn’t figure out whether it would work in situations where I
want to send a customized email to each recipient.
I tried doing something like
everything as before
…but the thread seems to quit as soon as the controller action is
finished rendering, and no emails are sent.