Reputation: 99
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.
Upvotes: 3
Views: 2195
Reputation: 1265
If you are using delayed_job, you have to run rake jobs:work
https://www.youtube.com/watch?v=AoGPaWEasxs
Upvotes: 0
Reputation: 7777
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)
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.
Upvotes: 1
Reputation: 132
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.
Upvotes: 0
Reputation: 506
You need to use some asynchronous backend like sidekiq
, delayed_job
or something else.
Upvotes: 1