Skip to content

Instantly share code, notes, and snippets.

@jwigal
Created February 6, 2012 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwigal/1749452 to your computer and use it in GitHub Desktop.
Save jwigal/1749452 to your computer and use it in GitHub Desktop.
=begin
Delayed Job will let you do this:
MyMailer.delay.mailer_action(args)
but you can't do this because of yaml serialization:
MyMailer.mailer_action(args).delay.deliver
Most cases this works fine, but I need this as a before_destroy callback. my data is gone when
the mailer fires.
Usage:
mail_object = MyMailer.mailer_action(args)
DelayedMailer.new(mail_object).deliver
=end
class DelayedMailer
attr_reader :mail_object, :settings
def initialize(mail_object)
@mail_source = mail_object.to_s
@settings = mail_object.delivery_method.settings
self
end
def mailer
m = Mail::Message.new(@mail_source)
m.delivery_method ::ActionMailer::Base.delivery_method, @settings
m
end
def deliver
mailer.deliver
end
handle_asynchronously :deliver
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment