Sends an email to each recipient.
deliver_by :email do |config|
config.mailer = "UserMailer"
config.method = :invoice_paid
config.params = ->{ params }
config.args = ->{ [1, 2, 3] }
config.kwargs = ->{ {body: "Hey there", subject: "Thanks for joining"} }
# Enqueues a separate job for sending the email using deliver_later.
# Deliveries already happen in jobs so this is typically unnecessary.
# config.enqueue = false
end-
mailer- RequiredThe mailer that should send the email
-
method: :invoice_paid- RequiredUsed to customize the method on the mailer that is called
-
params- OptionalUse a custom method to define the params sent to the mailer.
recipientandrecordwill be merged into the params. -
args- OptionalThe arguments for the
methodif it uses positional arguments (eg:def hello(a, b, c=1)) -
kwargs- OptionalThe arguments for the
methodif it uses keyword arguments (eg:def hello(a:, b:, c: 1)) -
enqueue: false- OptionalUse
deliver_laterto queue email delivery with ActiveJob. This isfalseby default as each delivery method is already a separate job.
Use YourMailer.with({ recipient: user }).mailer_method_name to set up a ActionMailer::Preview. And you can pass any number of params into the Hash but you will need the recipient key.
# test/mailers/previews/comment_mailer_preview.rb
class CommentMailerPreview < ActionMailer::Preview
def mailer_method_name
CommentMailer.with({ recipient: User.first }).mailer_method_name
end
end