PoBox

PoBox is a Ruby on Rails engine that provides inboxes and email addresses for your users.

Requirements

  1. ActiveStorage needs to be configured.
  2. ActionMailbox 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:

gem "po_box"

And then run:

$ bundle

Or install it yourself as:

$ 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.

  User.inboxes.first.address

  # => "some#[email protected]"

irb(main):003:0> u = User.last
  User Load (0.4ms)  SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT $1  [["LIMIT", 1]]
=>
#<User:0x000000011131a328
...
irb(main):004:0> 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]]
=>
#<PoBox::Inbox:0x00000001113119a8
 id: 1,
 emailable_type: "User",
 emailable_id: 1,
 address: "some#64b0",
 created_at: Thu, 04 May 2023 00:28:13.107181000 UTC +00:00,
 updated_at: Thu, 04 May 2023 00:28:13.107181000 UTC +00:00>
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]]
=>
#<PoBox::Email:0x00000001079c27e8
 id: 1,
 inbox_id: 1,
 cc: nil,
 from: "[email protected]",
 multipart: true,
 read: false,
 subject: "Something subjecty",
 to: "some#[email protected]",
 message_id: "[email protected]",
 body: "Hello World",
 created_at: Thu, 04 May 2023 00:28:44.171561000 UTC +00:00,
 updated_at: Thu, 04 May 2023 00:28:44.483199000 UTC +00:00>
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.