Skip to content

Callbacks and deliver short circuiting#72

Merged
jwoertink merged 2 commits intomainfrom
issues/65
Aug 15, 2022
Merged

Callbacks and deliver short circuiting#72
jwoertink merged 2 commits intomainfrom
issues/65

Conversation

@jwoertink
Copy link
Member

Fixes #65
Fixes #61

This PR allows you to setup before/after callbacks when sending an email as well as short circuiting an email from being delivered.

class FriendIsLiveEmail < BaseEmail
  def initialize(@recipient : Carbon::Emailable, @friend : User)
  end

  before_send do
    if !@recipient.wants_email_from_friend?(@friend)
      self.deliverable = false
    end
  end

  after_send do |response|
     MarkEmailAsRecentlySent.run(self, sent_at: Time.utc)
  end
end

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

Successfully merging this pull request may close these issues.

Adding before/after hooks for emails Short circuit email sending

2 participants