0

I am using sidekiq for sending mails in background. And i am getting this in sidekiq log

  def performed?
    create_activation_digest &&
    customer.save &&
    send_mail(:account_activation, { email: customer.email, activation_token: customer.activation_token }) # from here mailer method is being called
  end

class ApplicationMailer < ActionMailer::Base
  default from: 'lavo@cactimedia.biz'
  layout 'mailer'
  before_action :initialize_defaults

  private

  def initialize_defaults
    @greeting = "Dear User,"
    @signature = "The Lavo Team"
  end
end

class NotificationsMailer < ApplicationMailer

  def account_activation(args={})
    activation_token = args[:activation_token]
    email = args[:email]
    @activation_link = edit_api_activation_url(activation_token, email: email)

    mail(to: email)
  end
end

[ActiveJob] [ActionMailer::DeliveryJob] [2797cd49-dabe-4af0-a5a8-c47ae5e956b3] Performing ActionMailer::DeliveryJob from Sidekiq(mailers) with arguments: "NotificationsMailer", "password_digest", "deliver_now", #<GlobalID:0x00000007281480 @uri=#<URI::GID gid://lavo-laundry/Customer/6>>
[ActiveJob] [ActionMailer::DeliveryJob] [2797cd49-dabe-4af0-a5a8-c47ae5e956b3] Performed ActionMailer::DeliveryJob from Sidekiq(mailers) in 0.97ms

But mail are not being sent. Does somebody have any idea if i am missing something?

palash-kulkarni
  • 397
  • 3
  • 17
  • Can you add some more code where you are actually sending mails with sidekiq? – Pandurang Waghulde May 02 '17 at 10:14
  • Edited a question, added mailer method. – palash-kulkarni May 02 '17 at 10:22
  • Can you also add the code of your sidekiq job where you are calling this mailer? – Pandurang Waghulde May 02 '17 at 10:41
  • Did you try `.deliver` at the end of send_mail() ? – Md. Farhan Memon May 02 '17 at 11:16
  • Yes i tried, I found mail is not sent. But i can see in rails log as - [ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: e91ccd3f-059d-4be1-97e1-c77d6aeb9761) to Sidekiq(mailers) with arguments: "NotificationsMailer", "account_activation", "deliver_now", {:email=>"palash12@yopmail.com", :activation_token=>"d60b4251f1424ae1b2a1be1430e590ee"} And in Sidekiq log : [ActiveJob] [ActionMailer::DeliveryJob] [e91ccd3f-059d-4be1-97e1-c77d6aeb9761] Performed ActionMailer::DeliveryJob from Sidekiq(mailers) in 0.69ms – palash-kulkarni May 02 '17 at 11:27
  • then you better check mailer configuration, can you share the same? – Md. Farhan Memon May 02 '17 at 11:30
  • The same smtp configuration is working on development environment without sidekiq. I believe there is problem with sidekiq. I am new to it, can you please tell me how i can debug it? Like in delayed job i can check directly in active record. But what how to check error in sidekiq? – palash-kulkarni May 02 '17 at 11:33
  • ohh, i see.. I have been working with delayed job only. I don't know if you have tried this http://stackoverflow.com/questions/17743450/sidekiq-and-rails-4-actionmailer-never-delivers-emails – Md. Farhan Memon May 02 '17 at 11:49
  • Try sidekiq inline mode just to verify if your code is working. With Inline mode it doesn't enqueue job. It executes it immediately. https://github.com/mperham/sidekiq/wiki/Testing – Pandurang Waghulde May 02 '17 at 11:59

1 Answers1

2

Checks if the sidekiq settings have the following:

# config / sidekiq.yml
---
:queues:
  - mailers

or starts the sidekiq service with:

bundle exec sidekiq -q default -q mailers

as demonstrated at https://github.com/mperham/sidekiq/wiki/Active-Job#action-mailer

jonathanccalixto
  • 2,980
  • 2
  • 14
  • 10