I need to send massive email,I will use for brackground job Delayed Job, and have to create the email message in 3 languages (de, en, re), How can I cache the view so it doesn't have to create each time I'm calling the the mail method.
Asked
Active
Viewed 445 times
1 Answers
1
The deliver method is the one that sends the email, so you can do this:
def send_emails
# You can set here the email with attachments and all stuff
mail = MyMailer.send_message("demo@example.com")
body = mail.html_part.body
User.all.each do |u|
mail.to = u.email
mail.html_part.body = body.gsub(/user_id/, u.id)
mail.deliver
end
end
Of course it's better if you set this method for background processing.

Boris Barroso
- 1,802
- 2
- 22
- 41
-
if it's massive than perhaps better use `find_each` and not `all` ? – PL J Nov 26 '13 at 19:00