{"id":16805435,"url":"https://github.com/dewski/mail_gate","last_synced_at":"2025-03-22T02:31:27.966Z","repository":{"id":2606413,"uuid":"3589709","full_name":"dewski/mail_gate","owner":"dewski","description":null,"archived":false,"fork":false,"pushed_at":"2012-03-29T04:38:07.000Z","size":120,"stargazers_count":12,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T07:11:53.479Z","etag":null,"topics":["ruby"],"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/dewski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-03-01T07:03:00.000Z","updated_at":"2024-04-07T07:22:44.000Z","dependencies_parsed_at":"2022-07-09T09:16:20.224Z","dependency_job_id":null,"html_url":"https://github.com/dewski/mail_gate","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dewski%2Fmail_gate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dewski%2Fmail_gate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dewski%2Fmail_gate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dewski%2Fmail_gate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dewski","download_url":"https://codeload.github.com/dewski/mail_gate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244898099,"owners_count":20528331,"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":["ruby"],"created_at":"2024-10-13T09:48:13.501Z","updated_at":"2025-03-22T02:31:27.618Z","avatar_url":"https://github.com/dewski.png","language":"Ruby","readme":"MailGate [![Build Status](https://secure.travis-ci.org/dewski/mail_gate.png)](http://travis-ci.org/dewski/mail_gate)\n========\n\nMailGate is an additional delivery method for the [Mail](https://github.com/mikel/mail) gem that lets you restrict the delivery of mail to only whitelisted emails. Ideal for staging environments where you may be using production data and do not want them to recieve emails from your mailers when you submit comments, contact forms, or anything else that may trigger mail delivery.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'mail_gate'\n\nAnd then run:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install mail_gate\n\n## Usage\n\nMailGate works as a standalone extension to the [Mail](https://github.com/mikel/mail) gem or as a delivery method within Rails applications.\n\nTo configure MailGate, edit your ActionMailer configuration to use `:mail_gate` as the delivery method, then copy your existing settings to  `mail_gate_settings`:\n\n```ruby\n# config/environments/staging.rb\nCNN::Application.configure do\n  config.action_mailer.delivery_method = :smtp\n  config.action_mailer.smtp_settings = {\n    :address        =\u003e 'smtp.sendgrid.net',\n    :port           =\u003e '25',\n    :authentication =\u003e :plain,\n    :user_name      =\u003e ENV['SENDGRID_USERNAME'],\n    :password       =\u003e ENV['SENDGRID_PASSWORD'],\n    :domain         =\u003e ENV['SENDGRID_DOMAIN']\n  }\nend\n```\n\nBecomes:\n\n```ruby\n# config/environments/staging.rb\nCNN::Application.configure do\n  config.action_mailer.delivery_method = :mail_gate\n  config.action_mailer.mail_gate_settings = {\n    :whitelist        =\u003e /cnn.com/,\n    :delivery_method  =\u003e :smtp,\n    :delivery_settings =\u003e {\n      :address        =\u003e 'smtp.sendgrid.net',\n      :port           =\u003e '25',\n      :authentication =\u003e :plain,\n      :user_name      =\u003e ENV['SENDGRID_USERNAME'],\n      :password       =\u003e ENV['SENDGRID_PASSWORD'],\n      :domain         =\u003e ENV['SENDGRID_DOMAIN']\n    }\n  }\nend\n```\n\nWhen the email is sent, any emails that end up being extracted because they don't match the whitelist will be appended to the email's body so you know the intended recipients. So if you had a whitelist only for CNN.com, and you sent an email out to nytimes.com, it'd look something like:\n\n```\nThanks for reading our interesting article!\n\nExtracted Recipients: user@nytimes.com\n```\n\nIf you dislike that behavior, you can easily turn it off by setting `append_emails` to `false` in the settings.\n\n\n```ruby\n# config/environments/staging.rb\nCNN::Application.configure do\n  config.action_mailer.delivery_method = :mail_gate\n  config.action_mailer.mail_gate_settings = {\n    :whitelist     =\u003e /cnn.com/,\n    :append_emails =\u003e false\n  }\nend\n```\n\nBy default the emails send will have the same subject that they normally would. If you'd like to customize the subject to inform the reader where it was sent from you can do that with the `:subject_prefix` option:\n\n```ruby\n# config/environments/staging.rb\nCNN::Application.configure do\n  config.action_mailer.delivery_method = :mail_gate\n  config.action_mailer.mail_gate_settings = {\n    :whitelist        =\u003e /cnn.com/,\n    :subject_prefix   =\u003e '[Staging] ',\n    # ...\n  }\nend\n```\n\nNow your emails that are sent will have `[Staging] New comment on your article!` as the subject rather than just `New comment on your article!`. It's entirely up to you what you may put as the prefix, be it the current deploy git SHA, or if you want to send the server's hostname that sent the mail.\n\nEmail now sent within the staging environment will extract any recipient emails that don't match the whitelist. If after being filtered there aren't any recipients left because they were filtered out, no email will be sent:\n\n```\n\u003e Article.first.comments.each do |comment|\n\u003e   \"Email for: #{comment.user.email}\"\n\u003e   ArticleMailer.new_comment(article, comment).deliver\n\u003e end\n=\u003e Email for: john.doe@gmail.com\n=\u003e Email for: megatron@transformers.com\n=\u003e Email for: george@cnn.com\n=\u003e #\u003cMail::Message:70236177475420, Headers: \u003cFrom: no-reply@cnn.com\u003e, \u003cTo: george@cnn.com\u003e, \u003cSubject: [Staging] New comment on your article!\u003e\u003e\n```\n\nNotice only the email for `george@cnn.com` was delivered.\n\n## Using MailGate outside of Rails\n\nIf you have a Sinatra app or just using the Mail library in your Ruby project you can still use MailGate:\n\n```ruby\nrequire 'mail_gate'\n\nMail.defaults do\n  delivery_method MailGate::Filter,\n    :whitelist =\u003e /cnn.com/,\n    :subject_prefix =\u003e '[local] ',\n    :delivery_method =\u003e :file,\n    :location =\u003e '/dev/null'\nend\n```\n\nThen just deliver the email as normal:\n\n```ruby\nMail.deliver do\n  to 'george@cnn.com'\n  from 'no-reply@cnn.com'\n  subject 'Testing MailGate'\n  body 'Hi! :)'\nend\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Added some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n## Copyright\nCopyright © 2012 Garrett Bjerkhoel. See [LICENSE](https://github.com/dewski/mail_gate/blob/master/LICENSE) for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdewski%2Fmail_gate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdewski%2Fmail_gate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdewski%2Fmail_gate/lists"}