Pending Jobs and Mailer Action

I am having problems doing pending tasks with ActionMailer: Before doing the slow-motion:

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 fine):

 NotificationsMailer.new_message(@message).deliver 

After completing the Delayed job, all I did was change the delivery line:

 NotificationsMailer.delay.new_message(@message) 

In addition, I started the job queue using

 rake jobs:work 

I can see objects in the database if the task is closed, and I see that they appear after I started the worker, but nothing happens (not an email sent).

Update - other deferred tasks (not related to mail) work fine.

Can anyone help a newbie?

Thanks in advance!

+4
source share
2 answers

The first thing I'm looking at is the smtp settings in your environment, make sure this 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 am using old ruby, 1.8.7 and rails 2.3.8, so make sure the syntax is also correct.

+1
source

I spend a lot of time sending email using pending jobs, and finally it works.

In gem file

 gem 'delayed_job' gem 'delayed_job_active_record' 

In the controller

  def dtest UserMailer.delay.welcome_email render json:"Succes" return end 

In the mail program

 class UserMailer < ActionMailer::Base default from: " from@example.com " def welcome_email ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.smtp_settings = { address: "smtp.gmail.com", port: 587, domain: 'gmail.com', Authentication: "plain", enable_starttls_auto: true, user_name: ' your@gmail.com ', password: 'yourpassword' } mail(to: ' no-reply@gmail.com ', subject: 'Background Email Test').deliver end end 

After that, I just start the rails server and get started

 rake jobs:work 

Hope this helps you guys and emailing will work just fine using "delayed-jobs" :)

+5
source

All Articles