Rails 3/delayed_job - Wanted: Basic example of delayed mail

I've been trying to figure out how to send delayed mail using delayed_job with rails 3. I've tried pretty much every combination of feasible possibilities I can think of - I can get the mail to run in the background, I just can't get it to delay the sending to a future time. The delayed_jobs table in the db clears the tasks, the log says 'sent', the delayed_job task processor picks up the task & says sent without failure...but the mail is either:

  • sent immediately, or
  • simply doesn't arrive

if I try to send in the future.

If anyone could offer a bare-bones example of a rails 3 delayed_job that sends mail in the future, I'd be really appreciative. I'm sure lotsa folks do this so I suspect I'm missing something obvious. One (of countless) combinations I've tried below:

delayed_job: 2.1.2 рельсы: 3.0.3 actionmailer: 3.0.3

Контроллер:

class TestmailerController < ApplicationController
  def index
    Testmailer.delay.test_mail
  end

end

Mailer:

class Testmailer < ActionMailer::Base
  def test_mail
    mail(:to => '(myemailaddress@removedforprivacy.com', :from => '(removedforprivacy)@gmail.com', :subject => 'Testing Delayed Job', :content_type => 'text/plain').deliver
  end
  handle_asynchronously :test_mail, :run_at => Proc.new { 2.minutes.from_now }


end

соответствующая почтовая часть config / environment / development.rb:

  # Don't care if the mailer can't send
  config.action_mailer.raise_delivery_errors = true

  # Print deprecation notices to the Rails logger
  config.active_support.deprecation = :log

  config.action_mailer.default_url_options = { :host => 'localhost:3000' }

  ActionMailer::Base.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => 587,
    :domain => "gmail.com",
    :user_name => "(removedforprivacy)",
    :password => "(removedforprivacy)",
    :authentication => "plain",
    :enable_starttls_auto => true
  }

Команда задания:

rake jobs:work
5
задан PlankTon 21 December 2010 в 20:05
поделиться