3
votes

I have my production app running on AWS but am having issues with the active job - deliver_later on certain mailers. I am successfully sending all emails with deliver_later in development but there is something different in production. Certain mailers work with deliver_later but not my welcome mailer (welcomes new users). So I have to set deliver_now on this welcome mailer to have it actually send the email.

//doesn't work, email is not sent
UserMailer.welcome_email(self).deliver_later
//works
UserMailer.welcome_email(self).deliver_now

The log file from the server show this and nothing more when I use deliver_later:

[ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: d7114-464e-4a90-9721-126650) to Async(mailers) with arguments: "UserMailer", "welcome_email", "deliver_now", #>

Any help would be appreciated. Thanks.

4

4 Answers

1
votes

What ActiveJob backend are you using?

  • ActiveJob to provide asynchronous execution but does not provide asynchronicity itself.

You need to use some asynchronous backend like sidekiq, delayed_job or something else.

1
votes

deliver_now Delivers an email at a time.

If you use deliver_later you have to use ActiveJob runner like Sidekiq you can see this gist Sending emails with ActionMailer and Sidekiq also see this for basic Sidekiq email sent.

Enqueues the email to be delivered through Active Job. When the job runs it will send the email using deliver_now.

UserMailer.welcome_email(self).deliver_later(wait: 1.hour)

method-i-deliver_later

Basically, deliver_later is asynchronous. When you use this method, the email is not sent at the moment, but rather is pushed into a job's queue. If the job is not running, the email will not be sent. deliver_now will send the email at the moment, no matter what is the job's state. Here you can see the documentation for delivery methods.

0
votes

This is because you haven't set the time and rails picking up default time. and in log file also it shows that the deliver_later method is not being called yet.

Try using:

UserMailer.welcome_email(self).deliver_later(wait: 1.minute)

Then check the log after one min.

0
votes

If you are using delayed_job, you have to run rake jobs:work

https://www.youtube.com/watch?v=AoGPaWEasxs