{"id":13462977,"url":"https://github.com/zapnap/resque_mailer","last_synced_at":"2025-05-15T08:03:51.988Z","repository":{"id":56891965,"uuid":"464579","full_name":"zapnap/resque_mailer","owner":"zapnap","description":"Rails plugin for sending asynchronous email with ActionMailer and Resque","archived":false,"fork":false,"pushed_at":"2017-12-19T20:32:40.000Z","size":132,"stargazers_count":603,"open_issues_count":3,"forks_count":101,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-07T02:19:26.907Z","etag":null,"topics":["actionmailer","mailer","rails","resque"],"latest_commit_sha":null,"homepage":"https://github.com/zapnap/resque_mailer","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zapnap.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-01-08T23:31:14.000Z","updated_at":"2025-03-15T03:27:23.000Z","dependencies_parsed_at":"2022-08-21T00:20:45.924Z","dependency_job_id":null,"html_url":"https://github.com/zapnap/resque_mailer","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapnap%2Fresque_mailer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapnap%2Fresque_mailer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapnap%2Fresque_mailer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapnap%2Fresque_mailer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zapnap","download_url":"https://codeload.github.com/zapnap/resque_mailer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248869144,"owners_count":21174822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actionmailer","mailer","rails","resque"],"created_at":"2024-07-31T13:00:43.100Z","updated_at":"2025-04-14T11:22:32.180Z","avatar_url":"https://github.com/zapnap.png","language":"Ruby","funding_links":[],"categories":["Communication","Ruby","Gems"],"sub_categories":["Asynchronous E-Mail","Rails"],"readme":"# ResqueMailer\n[![Gem Version](https://badge.fury.io/rb/resque_mailer.png)](http://badge.fury.io/rb/resque_mailer)\n[![Build Status](https://secure.travis-ci.org/zapnap/resque_mailer.png)](http://travis-ci.org/zapnap/resque_mailer)\n\nA gem plugin which allows messages prepared by ActionMailer to be delivered\nasynchronously. Assumes you're using [Resque](https://github.com/resque/resque)\nfor your background jobs.\n\nNote that recent (2.0+) versions of Resque::Mailer only work with Rails 3.x or later.\nFor a version compatible with Rails 2, specify v1.x in your Gemfile.\n\n## Installation\n\nInstall the gem:\n\n    gem install resque_mailer\n\nIf you're using Bundler to manage your dependencies, you should add it to your Gemfile:\n\n    gem 'resque' # or a compatible alternative / fork\n    gem 'resque_mailer'\n\n## Usage\n\nInclude Resque::Mailer in your ActionMailer subclass(es) like this:\n\n```ruby\nclass MyMailer \u003c ActionMailer::Base\n  include Resque::Mailer\nend\n```\n\nNow, when `MyMailer.subject_email(params).deliver` is called, an entry\nwill be created in the job queue. Your Resque workers will be able to deliver\nthis message for you. The queue we're using is imaginatively named `mailer`,\nso just make sure your workers know about it and are loading your environment:\n\n    QUEUE=mailer rake environment resque:work\n\nNote that you can still have mail delivered synchronously by using the bang\nmethod variant:\n\n```ruby\nMyMailer.subject_email(params).deliver!\n```\n\nOh, by the way. Don't forget that **your async mailer jobs will be processed by\na separate worker**. This means that you should resist the temptation to pass\ndatabase-backed objects as parameters in your mailer and instead pass record\nidentifiers. Then, in your delivery method, you can look up the record from\nthe id and use it as needed. If you'd like, you can write your own serializer\nto automate such things; see the section on serializers below.\n\nIf you want to set a different default queue name for your mailer, you can\nchange the `default_queue_name` property like so:\n\n```ruby\n# config/initializers/resque_mailer.rb\nResque::Mailer.default_queue_name = 'application_specific_mailer'\n```\n\nThis is useful when you are running more than one application using\nresque_mailer in a shared environment. You will need to use the new queue\nname when starting your workers.\n\n    QUEUE=application_specific_mailer rake environment resque:work\n\nCustom handling of errors that arise when sending a message is possible by\nassigning a lambda to the `error_handler` attribute. There are two supported\nlambdas for backwards compatiability.\n\nThe first lamba will be deprecated in a future release:\n\n```ruby\nResque::Mailer.error_handler = lambda { |mailer, message, error|\n  # some custom error handling code here in which you optionally re-raise the error\n}\n```\n\nThe new lamba contains two other arguments, action and args, which allows\nmailers to be requeued on failure:\n\n```ruby\nResque::Mailer.error_handler = lambda { |mailer, message, error, action, args|\n  # Necessary to re-enqueue jobs that receieve the SIGTERM signal\n  if error.is_a?(Resque::TermException)\n    Resque.enqueue(mailer, action, *args)\n  else\n    raise error\n  end\n}\n```\n\n### Resque::Mailer as a Project Default\n\nIf you have a variety of mailers in your application and want all of them to use\nResque::Mailer by default, you can subclass ActionMailer::Base and have your\nother mailers inherit from an AsyncMailer:\n```ruby\n# config/initializers/resque_mailer.rb\nclass AsyncMailer \u003c ActionMailer::Base\n  include Resque::Mailer\nend\n\n# app/mailers/example_mailer.rb\nclass ExampleMailer \u003c AsyncMailer\n  def say_hello(user_id)\n    # ...\n  end\nend\n```\n\n### Writing an Argument Serializer\n\nBy default, the arguments you pass to your mailer are passed as-is to Resque. This\nmeans you cannot pass things like database-backed objects. If you'd like to write\nyour own serializer to enable such things, simply write a class that implements\nthe class methods `self.serialize(*args)` and `self.deserialize(data)` and set\n`Resque::Mailer.argument_serializer = YourSerializerClass` in your resque_mailer\ninitializer.\n\nThere's also Active Record serializer which allows you to pass AR\nmodels directly as arguments. To use it just do:\n`Resque::Mailer.argument_serializer = Resque::Mailer::Serializers::ActiveRecordSerializer`\n\n### Using with Resque Scheduler\n\nIf [resque-scheduler](https://github.com/bvandenbos/resque-scheduler) is\ninstalled, two extra methods will be available: `deliver_at` and `deliver_in`.\nThese will enqueue mail for delivery at a specified time in the future.\n\n```ruby\n# Delivers on the 25th of December, 2014\nMyMailer.reminder_email(params).deliver_at(Time.parse('2014-12-25'))\n\n# Delivers in 7 days\nMyMailer.reminder_email(params).deliver_in(7.days)\n\n# Unschedule delivery\nMyMailer.reminder_email(params).unschedule_delivery\n```\n## Testing\n\nYou don't want to be sending actual emails in the test environment, so you can\nconfigure the environments that should be excluded like so:\n```ruby\n# config/initializers/resque_mailer.rb\nResque::Mailer.excluded_environments = [:test, :cucumber]\n```\n\nNote: Define `current_env` if using Resque::Mailer in a non-Rails project:\n```ruby\nResque::Mailer.current_env = :production\n```\n\n## Note on Patches / Pull Requests\n\n* Fork the project.\n* Make your feature addition or bug fix.\n* Add tests for it. This is important so I don't break it in a future version unintentionally.\n* Commit, do not mess with rakefile, version, or history.\n  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)\n* Send me a pull request. Bonus points for topic branches.\n\n## Credits\n\nDeveloped by Nick Plante with help from a number of [contributors](https://github.com/zapnap/resque_mailer/contributors).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzapnap%2Fresque_mailer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzapnap%2Fresque_mailer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzapnap%2Fresque_mailer/lists"}