Search code examples
ruby-on-railsactionmailerdelayed-job

Delayed Jobs and Action Mailer


I am having trouble with implementing delayed jobs with my ActionMailer: Before Delayed Job Implementation:

class NotificationsMailer < ActionMailer::Base

  default :from => "noreply@mycompany.com"
  default :to => "info@mycompany.com"

  def new_message(message)
    @message = message
    mail(:subject => "[Company Notification] #{message.subject}")
  end

end

and called it using this line (it worked perfectly fine):

NotificationsMailer.new_message(@message).deliver

After the Delayed Job implementation all i did was change the deliver line to:

NotificationsMailer.delay.new_message(@message)

In addition, I started the jobs queue using

rake jobs:work

I can see the objects in the database if the job is closed and i can see they get popped after i start the worker but nothing happens (no email sent).

Update - Other Delayed Tasks (not related to mail) are working fine.

Can anyone help a newbie?

Thanks in advance!!


Solution

  • The first place I would look is the smtp settings in your environments, check to make sure that is correct:

    config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => 587,
    :domain => "gmail.com",
    :authentication => 'plain',
    :enable_starttls_auto => true,
    :user_name => "youremail@gmail.com",
    :password => "yourpassword"
    }
    config.action_mailer.default_charset = "utf-8"
    config.action_mailer.perform_deliveries = true
    config.action_mailer.raise_delivery_errors = true
    

    I use an old ruby, 1.8.7 and rails 2.3.8, so check to make sure the syntax is correct as well.