DEV Community

Discussion on: Using Mail Interceptors in Rails

Collapse
nuclearspike profile image
Paul

But doesn't the Interceptors version not do anything with the cc array? In the ApplicationMailer version, it iterates over the ccs and calls super(mail) for each. In the Interceptors module, it just creates a string of the cc's but then wipes out that array, then creates a string that says it is going to all of those users but there's no code that causes that to happen. Correct?

Collapse
drbragg profile image
Drew Bragg Author

Yup, I called that out after the example

Aside from the slight changes to how we handle CC's (which the team is happy with) this will do the same thing as the original code

We actually ended up missing the additional CC emails so that block has since been replaced with:

if mail.cc.present?
  mail.cc.each do |recipient|
    RawMailer.raw(
      "from" => mail.from,
      "recipients" => recipient,
      "subject" => "CCed version of: #{original_subject}",
      "plain_text_content" => mail.parts.first.body.to_s,
      "html_content" => mail.parts.last.body.to_s
    ).deliver_later
  end
  mail.cc = []
end
Enter fullscreen mode Exit fullscreen mode

So now it does basically the same thing.