{"id":13880196,"url":"https://github.com/bigbinary/mail_interceptor","last_synced_at":"2025-05-15T21:07:17.707Z","repository":{"id":25936121,"uuid":"29377516","full_name":"bigbinary/mail_interceptor","owner":"bigbinary","description":"This gem intercepts and forwards email to a forwarding address in a non-production environment.","archived":false,"fork":false,"pushed_at":"2025-03-22T23:57:49.000Z","size":64,"stargazers_count":104,"open_issues_count":1,"forks_count":12,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-04-19T12:36:00.919Z","etag":null,"topics":["gem","mail-interceptor","rails","ruby","ruby-on-rails"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bigbinary.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-01-17T02:44:22.000Z","updated_at":"2025-04-02T09:16:01.000Z","dependencies_parsed_at":"2024-06-19T10:02:24.639Z","dependency_job_id":"7654a3a2-516b-4da0-afda-b3e3c11c2b38","html_url":"https://github.com/bigbinary/mail_interceptor","commit_stats":{"total_commits":67,"total_committers":16,"mean_commits":4.1875,"dds":0.7761194029850746,"last_synced_commit":"ae1543acfad27eff3af1b5927885395eeb3ce558"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigbinary%2Fmail_interceptor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigbinary%2Fmail_interceptor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigbinary%2Fmail_interceptor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigbinary%2Fmail_interceptor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bigbinary","download_url":"https://codeload.github.com/bigbinary/mail_interceptor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253835420,"owners_count":21971783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gem","mail-interceptor","rails","ruby","ruby-on-rails"],"created_at":"2024-08-06T08:02:51.408Z","updated_at":"2025-05-15T21:07:17.685Z","avatar_url":"https://github.com/bigbinary.png","language":"Ruby","readme":"# Mail Interceptor\n\n- [Mail Interceptor](#mail-interceptor)\n  - [About](#about)\n  - [Usage](#usage)\n  - [only_intercept](#only_intercept)\n  - [deliver_emails_to](#deliver_emails_to)\n  - [forward_emails_to](#forward_emails_to)\n  - [ignore_bcc and ignore_cc](#ignore_bcc-and-ignore_cc)\n  - [Custom Environment](#custom-environment)\n  - [Prefixing email with subject](#prefixing-email-with-subject)\n  - [Brought to you by](#brought-to-you-by)\n\n## About\n\nThis gem intercepts and forwards email to a forwarding address in\na non-production environment. This is to ensure that in staging or \nin development by mistake we do not deliver emails to the real people. \nHowever we need to test emails time to time. \n\nRefer to https://github.com/bigbinary/wheel/blob/master/config/initializers/mail_interceptor.rb\nand you will notice that if an email ends with `deliver@bigbinary.com` then that emaill will be delivered.\n\nSo if Neeraj wants to test how the real email looks then he can use email `neeraj+deliver@bigbinary.com` and that email will be delivered. \nAs long as an email ends with `deliver@bigbinary.com` then that email will not be intercepted.\n\nIf client wants to test something and the client expects an email to be delivered then we need to add client's email here. \nSay the client's email is `michael@timbaktu.com`. \nChange that line to deliver_emails_to: `[\"deliver@bigbinary.com\", \"timbaktu.com\"]`. \nNow all emails ending with `timbaktu.com` would be delivered. \nIf you want only Michael should get email and other emails ending with \"timbaktu.com\" to be intercepted then change that line to deliver_emails_to: `[\"deliver@bigbinary.com\", \"michael@timbaktu.com\"]`.\n\n## Usage\n\n```ruby\n# There is no need to include this gem for production or for test environment\ngem 'mail_interceptor', group: [:development, :staging]\n```\n\n```ruby\n# config/initializers/mail_interceptor.rb\n\noptions = { forward_emails_to: 'intercepted_emails@domain.com',\n            deliver_emails_to: [\"@wheel.com\"] }\n\nunless (Rails.env.test? || Rails.env.production?)\n  interceptor = MailInterceptor::Interceptor.new(options)\n  ActionMailer::Base.register_interceptor(interceptor)\nend\n```\n\nDo not use this feature in test mode so that in tests\nyou can test against provided recipients of the email.\n\n## only_intercept\n\nPassing `only_intercept` is optional. If `only_intercept` is passed then only emails\nhaving the pattern mentioned in `only_intercept` will be intercepted. Rest of the emails\nwill be delivered.\n\nLet's say you want to only intercept emails ending with `@bigbinary.com` and forward the email.\nHere's how it can be accomplished.\n\n```ruby\nMailInterceptor::Interceptor.new({ forward_emails_to: 'intercepted_emails@domain.com',\n                                   only_intercept:  [\"@bigbinary.com\"] })\n```\n\nThis will only intercept emails ending with `@bigbinary.com` and forward the emails. Every other\nemail will be delivered.\n\nSuppose you want to intercept only some emails and not deliver them. You can do that by only\npassing the `only_intercept` option like so:\n\n```ruby\nMailInterceptor::Interceptor.new({ only_intercept: [\"@bigbinary.com\"] })\n```\n\nThis will intercept emails ending with `@bigbinary` and not deliver them.\n\n## deliver_emails_to\n\nPassing `deliver_emails_to` is optional. If no `deliver_emails_to`\nis passed then all emails will be intercepted and forwarded in\nnon-production environment.\n\nLet's say you want to actually deliver all emails having the pattern\n\"@BigBinary.com\". Here is how it can be accomplished.\n\n```ruby\nMailInterceptor::Interceptor.new({ forward_emails_to: 'intercepted_emails@domain.com',\n                                   deliver_emails_to: [\"@bigbinary.com\"] })\n```\n\nIf you want the emails to be delivered only if the email address is\n`qa@bigbinary.com` then that can be done too.\n\n```ruby\nMailInterceptor::Interceptor.new({ forward_emails_to: 'intercepted_emails@domain.com',\n                                   deliver_emails_to: [\"qa@bigbinary.com\"] })\n```\n\nNow only `qa@bigbinary.com` will get its emails delivered and all other emails\nwill be intercepted and forwarded.\n\nThe regular expression is matched without case sensitive. So you can mix lowercase\nand uppercase and it won't matter.\n\n## forward_emails_to\n\nPassing `forward_emails_to` is optional. If no `forward_emails_to`\nis passed then all emails will be intercepted and\nonly emails matching with `deliver_emails_to` will be delivered.\n\nBlank options can be provided to intercept and not send any emails.\n\n```ruby\nMailInterceptor::Interceptor.new({})\n```\n\nIt can take a single email or an array of emails.\n\n```ruby\nMailInterceptor::Interceptor.new({ forward_emails_to: 'intercepted_emails@bigbinary.com' })\n```\n\nIt can also take an array of emails in which case emails are forwarded to each of those emails in the array.\n\n```ruby\nMailInterceptor::Interceptor.new({ forward_emails_to: ['intercepted_emails@bigbinary.com',\n                                                       'qa@bigbinary.com' })\n```\n\n## ignore_bcc and ignore_cc\n\nBy default bcc and cc are ignored.\nYou can pass `:ignore_bcc` or `:ignore_cc` options as `false`,\nif you don't want to ignore bcc or cc.\n\n## Custom Environment\n\nBy default all emails sent in non production environment are\nintercepted. However you can control this behavior by passing `env` as\nthe key. It accepts any ruby objects which responds to `intercept?`\nmethod. If the result of that method is `true` then emails are\nintercepted otherwise emails are not intercepted.\n\nBelow is an example of how to pass a custom ruby object as value for\n`env` key.\n\nBesides method `intercept?` method `name` is needed if you have provided\n`subject_prefix`. This name will be appended to the `subject_prefix` to\nproduce something like `[WHEEL STAGING] Forgot password`. In this case\n`STAGING` came form `name`.\n\n```ruby\nclass MyEnv\n  def name\n    ENV[\"ENVIRONMENT_NAME\"]\n  end\n\n  def intercept?\n    ENV[\"INTERCEPT_MAIL\"] == '1'\n  end\nend\n\nMailInterceptor::Interceptor.new({ env: MyEnv.new,\n                                   forward_emails_to: ['intercepted_emails@bigbinary.com',\n                                   'qa@bigbinary.com' })\n```\n\n## Prefixing email with subject\n\nIf you are looking for automatically prefix all delivered emails with the application name and Rails environment\nthen we recommend using [email_prefixer gem](https://github.com/wireframe/email_prefixer) .\n\n## Brought to you by\n\u003ca href='http://BigBinary.com'\u003e\u003cimg src=\"https://raw.githubusercontent.com/bigbinary/bigbinary-assets/press-assets/PNG/logo-light-solid-small.png?raw=true\" width=\"200px\"/\u003e\u003c/a\u003e\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigbinary%2Fmail_interceptor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbigbinary%2Fmail_interceptor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigbinary%2Fmail_interceptor/lists"}