Coder Social home page Coder Social logo

ep_postmaster's Introduction

EP Postmaster

Build Status

A drop in solution for handling bounced emails from Mailgun

Usage: In your gemfile

gem ep_postmaster, github: "/cph/ep_postmaster", branch: "master"

and mount it in routes.rb

mount EpPostmaster::Engine => "/api/postmaster"

Setup

You'll need to add the api_key from mailgun along with the default address to send emails from. To do that, create a file in /config/initializers (ep_postmaster.rb in our case).

EpPostmaster.configure do |config|
  config.mailgun_api_key = "MAILGUN_API_KEY"
  config.mailer_sender = "[email protected]"
end

Overriding Default Mail Views

To override the mailer view, just create a file at /views/ep_postmaster/postmaster/bounced_email.txt.erb

You'll have access to the following instance variables.

  • @to (The recipient of the bounced email notification)
  • @recipient (The original recipient of the bounced email)
  • @original_subject (The original subject of the bounced email)
  • @error (The error code)

Additional options when a Bounced Email comes in

In your /config/initializers/ep_postmaster.rb file, you can specify an object or class that will handle the bounced email notice after the notification has been sent. To do that, set the bounced_email_handler param:

EpPostmaster.configure do |config|
  config.mailgun_api_key = "MAILGUN_API_KEY"
  config.mailer_sender = "[email protected]"
  config.bounced_email_handler = EmailAddress
end

Then, on the EmailAddress class, define a class level method called handle_bounced_email!. This method should accept two arguments: the recipient that bounced back, and the MailgunPost object with all params sent back from Mailgun.

Example:

class EmailAddress
...
  def self.handle_bounced_email!(email, mailgun_post)
    find_by(address: email).update_attribute(:undeliverable, true)
  end
...
end

ep_postmaster's People

Contributors

boblail avatar kobsy avatar theghall avatar lukebooth avatar

Watchers

Ben Govero avatar James Cloos avatar  avatar Kendall Park avatar Gene Doyel avatar Houston avatar Nicholas Weber avatar Ryan Shea  avatar  avatar Rob avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.