This blog is part of our Rails 5.2 series.
Rails allows sending emails asynchronously via Active Job.
ActionMailer::DeliveryJob as the default job
class to send emails.
This class is
method to handle exception and to do some housekeeping work.
One might need more control on the job class to retry the job under certain conditions or add more logging around exceptions.
Before Rails 5.2, it was not possible to use a custom job class for this purpose.
Rails 5.2 has added a feature to configure the job class per mailer.
By default, Rails will use the internal
class if the
delivery_job configuration is not present in the
Now, Rails will use
CustomNotifierDeliveryJob for sending emails for
As mentioned above
CustomNotifierDeliveryJob can be
further configured for logging, exception handling and reporting.
deliver_later will pass following arguments to the
method of the
- mailer class name
- mailer method name
- mail delivery method
- original arguments with which the mail is to be sent
We can also simply inherit from the
ActionMailer::DeliveryJob and override the