Module: EffectivePostmarkUser

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/effective_postmark_user.rb

Overview

EffectivePostmarkUsr

Mark your user model with effective_postmark_user

#<Postmark::InactiveRecipientError: You tried to send to recipient(s) that have been marked as inactive. Found inactive addresses: [email protected]. Inactive recipients are ones that have generated a hard bounce, a spam complaint, or a manual suppression.>

Defined Under Namespace

Modules: Base, ClassMethods

Instance Method Summary collapse

Instance Method Details

#postmark_inactive_recipient!Object

Triggered by the EffectivePostmarkMailer concern when a Postmark::InactiveRecipientError is raised



35
36
37
38
39
# File 'app/models/concerns/effective_postmark_user.rb', line 35

def postmark_inactive_recipient!
  return if email_delivery_error.present? # If we already marked invalid, don't mark again

  update_columns(email_delivery_error: 'Inactive Recipient', email_delivery_error_at: Time.zone.now)
end

#postmark_reactivate!Object

Triggered by an admin to reactivate the email address



51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/concerns/effective_postmark_user.rb', line 51

def postmark_reactivate!
  # Make an API request to reactivate this user
  EffectivePostmark.api.reactivate(self)

  # Send a reactivation email.
  # This could fail again and call postmark_inactive_recipient! behind the scenes
  message = EffectivePostmark.mailer_class.send(:reactivated, self).deliver_now
  return false if message.kind_of?(Exception)

  # This worked. We've been reactivated. Clear the error
  update_columns(email_delivery_error: nil, email_delivery_error_at: nil)
end

#postmark_suppression!(reason:, date:) ⇒ Object

Assigned by the rake task effective_postmark:assign_email_delivery_errors



42
43
44
45
46
47
48
# File 'app/models/concerns/effective_postmark_user.rb', line 42

def postmark_suppression!(reason:, date:)
  return if email_delivery_error.present? # If we already marked invalid, don't mark again

  date = (Time.zone.parse(date) rescue Time.zone.now) if date.kind_of?(String)

  update_columns(email_delivery_error: reason, email_delivery_error_at: date)
end