How to save emails sent with Noticed gem

  Kiến thức lập trình

I need to save all sent emails to database. The usual way I would do it would be to add a custom delivery job to ApplicationMailer and handle it in that job (I got the idea from

So my application_mailer.rb looks like this:

class ApplicationMailer < ActionMailer::Base

  self.delivery_job = ::Jobs::EmailDeliveryJob
  # ...

And the email_delivery_job.rb:

module Jobs
  class EmailDeliveryJob < ActionMailer::MailDeliveryJob

    queue_as :email_sending

    def perform(mailer, mail_method, delivery_method, args:, kwargs: nil, params: nil)
      response = super # Call the parent ActionMailer::MailDeliveryJob `perform` method to send the email

      # Store the record inside SentEmails
      user = params[:user]

      return if user.blank?

        email_type: "#{mailer}.#{mail_method}",
        subject: response.subject,
        content: response.body.to_s


It works fine when I call the mailer methods myself, but when an email is sent via Noticed (deliver_by :email, mailer: 'SomeMailer', method: :mail_type, format_data: :some_data, delay: 1.second) it skips the MailDeliveryJob.

I need to get the subject and body data from the email that is being sent by Noticed (at least), but I don’t know how. Ive tried extending the deliver method from the Noticed::Base (we’re using v1) but there is no useful data available at that point in the execution.

Any ideas?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website