I\'ve setup sidekiq in a rails 4 application for sending emails and processing background jobs. I have also devise which I am using devise_async and a typical contact form email
My setup is the same as this:
My code to run the mailer runs just fine and exits without any errors - but nothing is done and no email is sent. From my mailer:
logger.debug "about to mail"
logger.debug Rails.application.config.action_mailer.sendmail_settings.inspect
mail(to: purchase.email, subject: 'Your key')
logger.debug "mail done!"
That code is called from a sidekiq job. I can see in the rails logs the messages from the debug lines, confirming that this line of code is called. I also see the values of the sendmail_settings, confirming that the settings are the ones from development.rb.
So, just for giggles, I changed the settings to this in development.rb:
config.action_mailer.sendmail_settings = { :location => '/bogus/doesnt/exist' }
Of course after every one of these changes I purge the webroot and completely reload the app, and restart my servers.
Now I see the debug line print out the bogus config value, and still the mail(...) function is executing without any error. This is despite this
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
being set in the config (and being confirmed as being set by debug lines). My mail templates are rendered and the whole thing works, but the sendmail command is never executed, or even tried.
So then I looked at the source code in /var/lib/gems for both Mail and ActionMailer
Action Mailer source
...and I see that the mail(...) function ends with just "m" - so it returns the Mail object. I could not see anywhere in the mail(...) function where the mail is actually sent.
I added debug log lines to the send(...) function in the ActionMailer gem, and I see that in the logs. I added debug to the smtp deliver function in the Mail gem, and its never called.
So I tried calling "deliver" on that returned object thus:
outmail = mail(to: purchase.email, subject: 'Your key')
outmail.deliver
Now, my mail works. I have no idea what is going on here. If this is useful to anyone else I hope it helps. I have wasted a day of dev time on this, so I'm going to just take it as "it works" and check it in.
Actually i have same problem when use rails 4 version. The solution above not working for me. So, i have try sidekiq mailer gem https://github.com/andersondias/sidekiq_mailer and get it work well!
I found it, you have to run sidekiq like this:
RAILS_ENV=production bundle exec sidekiq -D
to run in production. It's the same issue as the assets precompile.
For anyone that might benefit from this, I ran sidekiq like this:
worker: bundle exec sidekiq -q default -q mailers -t 25 -c 3 ...
on the Procfile using heroku