Skip to content

Instantly share code, notes, and snippets.

@j-manu
Forked from leastbad/action_mailbox.md
Created January 16, 2023 08:35
Show Gist options
  • Save j-manu/ada57a930473c4d25e85e03b5132683d to your computer and use it in GitHub Desktop.
Save j-manu/ada57a930473c4d25e85e03b5132683d to your computer and use it in GitHub Desktop.
Action Mailbox: The Missing Manual

This is all you really need to know in order to make Action Mailbox work in development.

  1. Fire up ngrok http 3000 and make note of your subdomain for steps 3 and 8.
  2. Create a Mailgun account because they offer sandbox addresses; grab your domain from the Dashboard.
  3. Go into Receiving and create a catch-all route pointing to: https://XXX.ngrok.io/rails/action_mailbox/mailgun/inbound_emails/mime
  4. Add your Mailgun API key to your credentials:
action_mailbox:
  mailgun_api_key: API KEY HERE
  1. rails action_mailbox:install
  2. rake db:migrate
  3. rails generate mailbox incoming
  4. Add the following to your config/environments/development.rb
  config.action_mailbox.ingress = :mailgun
  config.hosts << "XXX.ngrok.io"
  1. Make sure your config/sidekiq.yml is monitoring the action_mailbox_routing queue.
  2. Configure your application_mailbox.rb with whatever routing you need; example below.
  3. Configure your incoming_mailbox.rb as you wish; example below.

You should now be able to send an email to test@MAILGUN-SANDBOX-DOMAIN.

class ApplicationMailbox < ActionMailbox::Base
# routing /^info@/i => :incoming
routing all: :incoming
end
class IncomingMailbox < ApplicationMailbox
# before_processing
# around_processing
# after_processing
# before_processing do
# unless User.exist?(email: mail.from)
# bounce_with Mailer.user_not_found(mail)
# end
# end
def process
# puts mail.methods - Object.methods
# mail.content, mail.subject, mail.has_attachments?
puts mail.inspect
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment