← Home

Rails Generate mailbox

Reference & Command Builder

Published: 2023-05-11
Author: Harrison Broadbent
Type: Reference & Command Builder

Rails Generate Mailbox

Rails Generate Mailbox (rails g mailbox) is the generator for ActionMailbox mailboxes. ActionMailbox routes incoming emails to mailboxes, which are similar to controllers, but for incoming emails.

Mailboxes handles incoming emails by converting them to InboundEmail records; Mailboxes handle storing inbound emails, and incinerating old emails (after 30 days, by default).

Before generating a mailbox, you'll need to run the installation task —

 bin/rails action_mailbox:install
 bin/rails db:migrate

You'll also need to connect ActionMailbox to a service for email ingress, like Sendgrid, Postmark, Mailgun etc. You should refer to the ActionMailbox configuration guide for instructions.

Command Builder for rails g mailbox

rails g mailbox 

Mailbox name

Generator Options

Runtime Options

# Command Options
❯ rails g mailbox

  rails generate mailbox NAME [options]

      [--skip-namespace], [--no-skip-namespace]              # Skip namespace (affects only isolated engines)
      [--skip-collision-check], [--no-skip-collision-check]  # Skip collision check
  -t, [--test-framework=NAME]                                # Test framework to be invoked
                                                             # Default:

Runtime options:
  -f, [--force]                    # Overwrite files that already exist
  -p, [--pretend], [--no-pretend]  # Run but do not make any changes
  -q, [--quiet], [--no-quiet]      # Suppress status output
  -s, [--skip], [--no-skip]        # Skip files that already exist

# Command Description
    Generates a new mailbox class in app/mailboxes and invokes your template
    engine and test framework generators.

    bin/rails generate mailbox inbox

    creates an InboxMailbox class and test:
        Mailbox:  app/mailboxes/inbox_mailbox.rb
        Test:     test/mailboxes/inbox_mailbox_test.rb