I am trying to figure out if it is possible to use ActionMailer without Rails to render the html.erb view once, and then send it several times, just using different emails: to?
NOTE. I DO NOT use the full Rails stack, just ActionMailer
So in the mailer class
class MyMailer < ActionMailer::Base default :from => ' johndoe@example.com ', :subject => 'New Arrivals!' def new_products(customer, new_products) @new_products = new_products mail :to => customer.email do |format| format.html end end end
Then in the client code we need to get new products and customers.
products = Product.new_since_yesterday customers = Customer.all customers.each do |c| MyMailer.new_products(c, products).deliver end
Let's say this is sent once a day, so we want to receive new products only from the moment we sent the letter. We want to do this only once, as new products today will not change between e-mail messages. As far as I know, this will trigger a render every time an email is created and sent.
Is there a way to tell ActionMailer to do this only once, and then somehow reference the object containing the rendered view. This will cut out all the time it takes for the render to do this. Sent email addresses will be changed, but email content will not.
Obviously, for a large number of emails, you simply do not scroll through the list and do not create / send emails. You can use a queue for this. In the general case, when you do not need to repeatedly render the rendering step, how do you do it once and use this result for all letters?
Potentially, my unfamiliarity with ActionMailer does not allow me here.