Git Product home page Git Product logo

recipient_interceptor's Introduction

recipient_interceptor

Use this Ruby gem to avoid emailing your users from non-production environments.

# Gemfile
gem "recipient_interceptor"

# config/environments/staging.rb
Mail.register_interceptor(
  RecipientInterceptor.new("[email protected]")
)

# config/environments/production.rb
My::Application.configure do
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address: ENV.fetch("SMTP_ADDRESS"), # example: "smtp.sendgrid.net"
    authentication: :plain,
    domain: ENV.fetch("SMTP_DOMAIN"), # example: "heroku.com"
    enable_starttls_auto: true,
    password: ENV.fetch("SMTP_PASSWORD"),
    port: "587",
    user_name: ENV.fetch("SMTP_USERNAME")
  }
end

Email will be intercepted and delivered to the provided address with headers X-Intercepted-To, X-Intercepted-Cc, and X-Intercepted-Bcc added.

Configuration options and examples

Deliver intercepted email to multiple email addresses:

Mail.register_interceptor(
  RecipientInterceptor.new(["[email protected]", "[email protected]"])
)

Use a comma-delimited string:

Mail.register_interceptor(
  RecipientInterceptor.new("[email protected],[email protected]")
)

Use an environment variable:

# heroku config:set EMAIL_RECIPIENTS="[email protected],[email protected]" --app staging
Mail.register_interceptor(
  RecipientInterceptor.new(ENV["EMAIL_RECIPIENTS"])
)

Prefix the subject line with static text:

Mail.register_interceptor(
  RecipientInterceptor.new(
    ENV["EMAIL_RECIPIENTS"],
    subject_prefix: "[staging]",
  ),
)

Prefix the subject line with contents from the original message:

Mail.register_interceptor(
  RecipientInterceptor.new(
    ENV["EMAIL_RECIPIENTS"],
    subject_prefix: proc { |msg| "[staging] [#{(msg.to + msg.cc + msg.bcc).sort.join(",")}]" }
  ),
)

The object passed to the proc is an instance of Mail::Message.

Alternatives

Contributing

Fork the repo.

bundle
bundle exec rake

Make a change. Run tests. Open a pull request. Discuss/address any feedback with maintainer. Maintainer will merge.

recipient_interceptor's People

Contributors

croaky avatar dependabot[bot] avatar jassa avatar r00k avatar reiz avatar ruckus avatar uri 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.