Module: EffectivePostmarkMailer

Extended by:
ActiveSupport::Concern
Included in:
Effective::PostmarkMailer
Defined in:
app/mailers/concerns/effective_postmark_mailer.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#effective_postmark_error(exception) ⇒ Object



58
59
60
61
62
63
# File 'app/mailers/concerns/effective_postmark_mailer.rb', line 58

def effective_postmark_error(exception)
  Rails.logger.info "\e[31m\e[1mEMAIL FAILED\e[0m\e[22m" # bold red
  Rails.logger.info "#{exception.inspect}"

  true
end

#effective_postmark_inactive_recipient_error(exception) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/mailers/concerns/effective_postmark_mailer.rb', line 31

def effective_postmark_inactive_recipient_error(exception)
  # Read the current app's Tenant if defined
  tenant = if defined?(Tenant)
    Tenant.current || raise("Missing tenant in effective_postmark exception")
  end

  # Find the user to associate it with
  user_klass = (tenant ? Tenant.engine_user(tenant) : "User".safe_constantize)
  raise("Expected an effective_postmark_user") unless user_klass.try(:effective_postmark_user?)

  # All recipients
  recipients = (Array(exception.recipients) - [nil, "", " "]).map { |email| email.downcase.strip }

  # Find each user and mark them postmark_inactive and make a log
  recipients.each do |email|
    user = user_klass.find_for_database_authentication(email: email)

    if user.present?
      user.postmark_inactive_recipient!
    end

    ::EffectiveLogger.email("[ERROR] Inactive Recipient - #{email}", user: user, error_code: exception.error_code, message: exception.message)
  end

  true
end