Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible that I log success or failure of delivering mail ? #2370

Closed
honeyl3oom opened this issue Jun 1, 2015 · 2 comments
Closed

Comments

@honeyl3oom
Copy link

I want to log the success of failure into database when email delivered. (with aynsc. deliver_later)
It looks like callback function (after_deliver(?)).
Is it possible ??

@mperham
Copy link
Collaborator

mperham commented Jun 1, 2015

Could you ask this question on StackOverflow? I don't know the answer.

@mperham mperham closed this as completed Jun 1, 2015
@honeyl3oom
Copy link
Author

I solve this below!

#app/workers/mails_worker.rb
class MailsWorker
  # refer to mail_type in mail_log
  include Sidekiq::Worker
  sidekiq_options retry: 3
  sidekiq_retry_in do |count|
    600 
  end 

  def perform(hash)
    type = hash["type"]
    success = false
    begin
      if type == 100 
        hash["partner"] = Company.find_by_id(hash["partner_id"])
        if hash["partner"].nil?
          return
        end 
        PartnerMailer.alarm_mail(hash).deliver # config.raise_delivery_errors = true (Rails 4.1.4)
      end 
      success = true
    rescue Exception
      success = false
    end 
    if success
      MailLog.create(mail_type:type, email:hash["partner"].email)
    else
      raise "Email send failed Retry!" #fail
    end 
  end 
end

I think this works well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants