Note that there are some explanatory texts on larger screens.

plurals
  1. POResend same email in ActionMailer
    primarykey
    data
    text
    <p>I need to send big amount of emails. Building email in this case is quite heavy task, so I'm trying to cache and reuse it:</p> <pre><code>mail = Rails.cache.fetch("newsletters/#{newsletter.id}") do NewsletterMailer.products(newsletter) end recipients.find_each do |user| mail.to = user.email mail.deliver end </code></pre> <p>But with this code only first recipient receives email. Seems like that the same email can't be send more than once. Than I tried to dup it:</p> <pre><code>recipients.find_each do |user| m = mail.dup m.to = user.email m.deliver end </code></pre> <p>The same result. Just to check this assumption instead of dup I tried:</p> <pre><code>m = Marshal.load(Marshal.dump(mail)) </code></pre> <p>Then email is delivered to all recipients.</p> <p>So my question is how can "reset" (or smth like that) email and send it again?</p> <p>ActionMailer version is 3.1.12</p> <p>UPD</p> <p>The problem was that emails had the same 'Message-ID' header. In development I was using GMail and don't know exactly ActionMailer or GMail wasn't sending. At the moment I don't have opportunity to test it. Anyway same 'Message-ID' is incorrect so I added <code>add_message_id</code> to generate new header for each email:</p> <pre><code>recipients.find_each do |user| mail.add_message_id mail.to = user.email mail.deliver end </code></pre> <p>Maybe someone will find it helpful or someone can give a clearer explanation.</p> <p>I haven't tried Peer Allan's answer. But it seems like that it also can be solution, that's why I accepted it</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload