Coder Social home page Coder Social logo

delayed_mailhopper's Introduction

DelayedMailhopper Build Status

DelayedMailhopper provides a simple solution to queue, deliver and archive emails in Rails apps. It extends Mailhopper and uses DelayedJob to queue delivery jobs asynchronously.

Requirements

  • Rails 3.1+
  • DelayedJob
  • Mailhopper

Installation

Add to your project's Gemfile:

gem 'delayed_mailhopper'

Install with bundler (note: also installs dependencies such as DelayedJob and Mailhopper):

bundle install

Configure Mailhopper

If you haven't already, you'll need to run generators for Mailhopper and then migrate your database.

rails g mailhopper
rake db:migrate

Configure DelayedJob

ActiveRecord Backend

Add the gem to your Gemfile:

gem 'delayed_job_active_record'

Run the generator to create the migration for the delayed_job table.

rails g delayed_job:active_record
rake db:migrate

see the README: https://github.com/collectiveidea/delayed_job_active_record

Mongoid backend

Add the gem to your Gemfile:

gem 'delayed_job_mongoid'

Create the indexes (and don't forget to do this on your production database):

script/rails runner 'Delayed::Backend::Mongoid::Job.create_indexes'

see the README: https://github.com/collectiveidea/delayed_job_mongoid

Troubleshooting

If you've cleared your delayed job queue and need to regenerate jobs for all unsent emails, try the following from your Rails console (rails c):

DelayedMailhopper::Email.unsent.each { |email| email.enqueue }

References

Please see the README for Mailhopper: https://github.com/cerebris/mailhopper

And for DelayedJob: https://github.com/collectiveidea/delayed_job/

Copyright

Copyright (c) 2011 Cerebris Corporation. This is free software released under the MIT License (see MIT-LICENSE for details).

delayed_mailhopper's People

Contributors

dgeb avatar linjunpop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

delayed_mailhopper's Issues

Is there a way to specify the 'email' queue with DJ3?

I was planning to setup a dedicated email worker as we're using a lot of DJ and I'd like to avoid delays if the rest of the queue is backed up for some reason. Is it possible to specify that the job go to the 'email' queue?

Is there any type of audit job?

In the event that a delayed job queue gets locked up and somebody opts to clear the entire queue (it's happened before :-) is there a way to recreate delayed jobs for all unsent mail in the emails table?

Delayed job cannot process email

Hi all.
I'm using DelayedMailhopper (with MailHopper and Delayed Jobs). When I send my email, I get it to Email table and the task to be executed to DelayedJobs table. But when DelayedJobs daemon tries to execute this task, I get this error:

BEGIN
Delayed::Backend::ActiveRecord::Job Load (0.5ms) SELECT "delayed_jobs".* FROM "delayed_jobs" WHERE "delayed_jobs"."id" = $1 LIMIT 1 FOR UPDATE ["id", 1218] UPDATE "delayed_jobs" SET "locked_at" = '2013-04-11 10:02:24.582308', "locked_by" = 'host:anahorets-iMac-4.local pid:17549', "updated_at" = '2013-04-11 10:02:24.586329' WHERE "delayed_jobs"."id" = 1218
(0.5ms) COMMIT
(0.4ms) BEGIN
(0.7ms) UPDATE "delayed_jobs" SET "last_error" = 'Job failed to load: invalid subclass. Handler: "--- !ruby/struct:DelayedMailhopper::SendJob \nid: 1212\n"
/usr/local/opt/rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:87:in rescue in payload_object'' /usr/local/opt/rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:85:inpayload_object''
/usr/local/opt/rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:95:in block in invoke_job'' /usr/local/opt/rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:60:incall''
/usr/local/opt/rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/delayed_job-

I think the problem is here:

delayed_jobs" SET "last_error" = 'Job failed to load: invalid subclass. Handler: "--- !ruby/struct:DelayedMailhopper::SendJob \nid: 1212\n

But I dont know how to resolve it.

Infinite loop sending emails

After creating email in controller Partners::InvitationMailer.invite().deliver new row is added to Emails table but

Mailhopper in method send! after code mail.deliver adds second duplicit row in Emails table and this continue in loop.

def send!(delivery_method = nil)
  mail = Mail.new(self.content)
  mail[:bcc] = self.bcc_address unless self.bcc_address.blank?
  Base.mailer_class.wrap_delivery_behavior(mail, delivery_method || Base.default_delivery_method)
  mail.deliver # AFTER THIS CODE NEW ROW TO EMAILS TABLE IS ADDED
  self.sent_at = Time.now
  self.save!
end

Any idea guys?

Timeout::Error

Hi, I am trying to use mailhopper and I am getting DelayedMailhopper::SendJob failed with Timeout::Error.

Does the smtp configuration in application.rb is used by Mailhopper to send the email? Mine is configured to use gmail as follow:

config.action_mailer.delivery_method = :mailhopper
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'gmail.com',
:user_name => 'username',
:password => 'password',
:authentication => 'plain',
:enable_starttls_auto => true }

Sorry to bother with this question, but I couldn't find any documentation about this.

Thanks in advance,
Gus

how to write code for delayed mailhopper

Hi guys, after some configuration follow read me, I want to ask you question about how to write code for delayed mailhopper?

I write these code for active mailer :

define mailer class

class CandidateMailer < ActionMailer::Base
default from: "[email protected]"

def registration_confirmation(candidate)
@candidate = candidate
mail(:to => candidate.email, :subject => "xxx")
end
end

send email

CandidateMailer.registration_confirmation(candidate).deliver

and I wonder what kind of code do I need if I use delayed mailhopper?
Thanks for reply.

Possibly Ruby 2.1.5 issue with `Delayed::Job.enqueue(SendJob.new(1))`?

After upgrading to Ruby 2.1.5 from Ruby 2.1.2, sending emails with delayed_mailhopper creates this error:

ArgumentError: wrong number of arguments (1 for 0)

…ailhopper-0.0.7/app/models/delayed_mailhopper/email.rb:   9:in `initialize'
…ailhopper-0.0.7/app/models/delayed_mailhopper/email.rb:   9:in `new'
…ailhopper-0.0.7/app/models/delayed_mailhopper/email.rb:   9:in `enqueue'
…0/gems/mailhopper-0.3.0/app/models/mailhopper/email.rb:  25:in `create_from_mail'
…by/2.1.0/gems/mailhopper-0.3.0/lib/mailhopper/queue.rb:   7:in `deliver!'
…/bundle/ruby/2.1.0/gems/mail-2.5.4/lib/mail/message.rb:2129:in `do_delivery'
…/bundle/ruby/2.1.0/gems/mail-2.5.4/lib/mail/message.rb: 232:in `block in deliver'
…/bundle/ruby/2.1.0/gems/mail-2.5.4/lib/mail/message.rb: 232:in `deliver'
…ms/delayed_job-4.0.0/lib/delayed/performable_mailer.rb:   6:in `perform'
…1.0/gems/delayed_job-4.0.0/lib/delayed/backend/base.rb: 105:in `block in invoke_job'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  60:in `call'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  60:in `block in initialize'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  65:in `call'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  65:in `execute'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  38:in `run_callbacks'
…1.0/gems/delayed_job-4.0.0/lib/delayed/backend/base.rb: 102:in `invoke_job'
…uby/2.1.0/gems/delayed_job-4.0.0/lib/delayed/worker.rb: 206:in `block (2 levels) in run'
                   /usr/local/lib/ruby/2.1.0/timeout.rb:  91:in `block in timeout'
                   /usr/local/lib/ruby/2.1.0/timeout.rb: 101:in `call'
                   /usr/local/lib/ruby/2.1.0/timeout.rb: 101:in `timeout'
…uby/2.1.0/gems/delayed_job-4.0.0/lib/delayed/worker.rb: 206:in `block in run'
…uby/2.1.0/gems/delayed_job-4.0.0/lib/delayed/worker.rb: 205:in `run'
…uby/2.1.0/gems/delayed_job-4.0.0/lib/delayed/worker.rb: 267:in `block in reserve_and_run_one_job'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  60:in `call'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  60:in `block in initialize'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  65:in `call'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  65:in `execute'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  38:in `run_callbacks'
…uby/2.1.0/gems/delayed_job-4.0.0/lib/delayed/worker.rb: 267:in `reserve_and_run_one_job'
…uby/2.1.0/gems/delayed_job-4.0.0/lib/delayed/worker.rb: 189:in `block in work_off'
…uby/2.1.0/gems/delayed_job-4.0.0/lib/delayed/worker.rb: 188:in `times'
…uby/2.1.0/gems/delayed_job-4.0.0/lib/delayed/worker.rb: 188:in `work_off'
…uby/2.1.0/gems/delayed_job-4.0.0/lib/delayed/worker.rb: 153:in `block (4 levels) in start'
…uby/2.1.0/gems/delayed_job-4.0.0/lib/delayed/worker.rb: 152:in `block (3 levels) in start'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  60:in `call'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  60:in `block in initialize'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  65:in `call'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  65:in `execute'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  38:in `run_callbacks'
…uby/2.1.0/gems/delayed_job-4.0.0/lib/delayed/worker.rb: 151:in `block (2 levels) in start'
…uby/2.1.0/gems/delayed_job-4.0.0/lib/delayed/worker.rb: 150:in `loop'
…uby/2.1.0/gems/delayed_job-4.0.0/lib/delayed/worker.rb: 150:in `block in start'
…s/delayed_job-4.0.0/lib/delayed/plugins/clear_locks.rb:   7:in `call'
…s/delayed_job-4.0.0/lib/delayed/plugins/clear_locks.rb:   7:in `block (2 levels) in <class:ClearLocks>'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  78:in `call'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  78:in `block (2 levels) in add'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  60:in `call'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  60:in `block in initialize'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  78:in `call'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  78:in `block in add'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  65:in `call'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  65:in `execute'
…/2.1.0/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:  38:in `run_callbacks'
…uby/2.1.0/gems/delayed_job-4.0.0/lib/delayed/worker.rb: 149:in `start'
…ruby/2.1.0/gems/delayed_job-4.0.0/lib/delayed/tasks.rb:   9:in `block (2 levels) in <top (required)>'
…ed/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb: 240:in `call'
…ed/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb: 240:in `block in execute'
…ed/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb: 235:in `each'
…ed/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb: 235:in `execute'
…ed/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb: 179:in `block in invoke_with_call_chain'
                   /usr/local/lib/ruby/2.1.0/monitor.rb: 211:in `mon_synchronize'
…ed/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb: 172:in `invoke_with_call_chain'
…ed/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb: 165:in `invoke'
…le/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb: 150:in `invoke_task'
…le/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb: 106:in `block (2 levels) in top_level'
…le/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb: 106:in `each'
…le/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb: 106:in `block in top_level'
…le/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb: 115:in `run_with_threads'
…le/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb: 100:in `top_level'
…le/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:  78:in `block in run'
…le/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb: 176:in `standard_exception_handling'
…le/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:  75:in `run'

I've narrowed it down to this line of code Delayed::Job.enqueue(SendJob.new(self.id)) (view code) and I've tried just pasting Delayed::Job.enqueue(SendJob.new(1)) and SendJob.new(1) into rails console, and I get the same errors:

ArgumentError: wrong number of arguments (1 for 0)
    from (irb):14:in `initialize'
    from (irb):14:in `new'
    from (irb):14
    from /var/.../web_head/shared/bundle/ruby/2.1.0/gems/railties-3.2.21/lib/rails/commands/console.rb:47:in `start'
    from /var/.../web_head/shared/bundle/ruby/2.1.0/gems/railties-3.2.21/lib/rails/commands/console.rb:8:in `start'
    from /var/.../web_head/shared/bundle/ruby/2.1.0/gems/railties-3.2.21/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

I'm running Rails 2.3.21 for both Ruby environments. It still works in the older Ruby 2.1.2 environment. Any thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.