# PoBox PoBox is a Ruby on Rails engine that provides inboxes and email addresses for your users. ## Requirements 1. [ActiveStorage](https://edgeguides.rubyonrails.org/active_storage_overview.html) needs to be configured. 2. [ActionMailbox](https://edgeguides.rubyonrails.org/action_mailbox_basics.html) needs to be configured. 3. A model that the inbox and emails will be associated with needs to exist in the host application. e.g. `User` or `Account`. ## Installation Add this line to your application's Gemfile: ```ruby gem "po_box" ``` And then run: ```bash $ bundle ``` Or install it yourself as: ```bash $ gem install po_box ``` ## Configuration **IMPORTANT:** Make sure you have ActiveStorage and ActionMailbox installed and configured. 1. `bin/rails po_box:install:migrations` 2. `bin/rails g po_box emailable_model` (where `emailable_model` is the name of the model in your application you want to associate inboxes and email addresses to, e.g. `user`) 3. `bin/rails db:migrate` 4. `bin/rails po_box:backfill_emailables` ## Limitations 1. Can only be applied to one model per application, for now. ## Usage Visit http://localhost:3000/rails/conductor/action_mailbox/inbound_emails to send an email to your app. Send the email to the address that is associated with the emailable model. e.g. ```ruby User.inboxes.first.address # => "some#64b0@yourapp.com" ``` ```ruby irb(main):003:0> u = User.last User Load (0.4ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT $1 [["LIMIT", 1]] => # u.inboxes.first PoBox::Inbox Load (0.4ms) SELECT "po_box_inboxes".* FROM "po_box_inboxes" WHERE "po_box_inboxes"."emailable_id" = $1 AND "po_box_inboxes"."emailable_type" = $2 ORDER BY "po_box_inboxes"."id" ASC LIMIT $3 [["emailable_id", 1], ["emailable_type", "User"], ["LIMIT", 1]] => # irb(main):005:0> irb(main):005:0> u.inboxes.first.emails.last PoBox::Inbox Load (0.5ms) SELECT "po_box_inboxes".* FROM "po_box_inboxes" WHERE "po_box_inboxes"."emailable_id" = $1 AND "po_box_inboxes"."emailable_type" = $2 ORDER BY "po_box_inboxes"."id" ASC LIMIT $3 [["emailable_id", 1], ["emailable_type", "User"], ["LIMIT", 1]] PoBox::Email Load (0.5ms) SELECT "po_box_emails".* FROM "po_box_emails" WHERE "po_box_emails"."inbox_id" = $1 ORDER BY "po_box_emails"."id" DESC LIMIT $2 [["inbox_id", 1], ["LIMIT", 1]] => # irb(main):006:0> ``` ## Contributing Bug reports and pull requests are always welcome! ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).