I tried to figure out how to send delayed mail using delayed_job with rails 3. I tried almost any combination of the possible possibilities that I can think of - I can make mail work in the background, I just can not make it delay sending in the future. The delayed_jobs table in db clears the tasks, the log says “sent”, the delayed_job task processor picks up the task and sends the message without fail ... but mail:
- shipped immediately or
- just doesn't come
if I try to send in the future.
If someone could offer an example from the bare side of rails 3 delayed_job, which sends mail in the future, I would be very grateful. I'm sure many people do this, so I suspect I'm missing out on something obvious. One of the countless combinations I've tried below:
delayed_job: 2.1.2 rails: 3.0.3 actionmailer: 3.0.3
Controller:
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
corresponding mail part config / environment / development.rb:
config.action_mailer.raise_delivery_errors = true
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
}
Job Command:
rake jobs:work
source
share