Professional Documents
Culture Documents
ActionMailbox Slides
ActionMailbox Slides
The inbound emails are turned into `InboundEmail` records using Active
Record and feature life cycle tracking
These inbound emails are routed asynchronously using Active Job to one or
several dedicated mailboxes, which are capable of interacting directly
with the rest of your domain model.
https://actionmailbox:PASSWORD@example.com/rails/action_mailbox/postmark/inbound_emails
Reason #2
fi
Running the Generator
Run built in generator
$ bin/rails action_mailbox:install
$ bin/rails db:migrate
Getting Started
What’s added
bin/rails action_mailbox:install
# app/mailboxes/application_mailbox.rb
class ApplicationMailbox < ActionMailbox::Base
# routing /something/i => :somewhere
end
Getting Started
Email Routing Tips
# app/mailboxes/application_mailbox.rb
class ApplicationMailbox < ActionMailbox::Base
routing all: :support
# routing(/support\./i => :support)
end
Getting Started
Generating your rst Mailbox
https://localhost:3000/rails/conductor/action_mailbox/inbound_emails
Rails Conductor
Sending Inbound Emails
• By form
• Send Email by Raw Source
Reason #3
t.timestamps
def mail
@mail ||= Mail.from_source(source)
end
def source
@source ||= raw_email.download
end
def processed?
delivered? || failed? || bounced?
end
end
end
ActionMailbox::InboundEmail
inbound_email.raw_email
=> #<ActiveStorage::Attached::One:0x0000000112e396e0
@name="raw_email",
@record=#<ActionMailbox::InboundEmail:0x0000000110523968>
inbound_email.source
=> "Date: Mon, 11 Mar 2024 11:56:41..."
inbound_email.mail.class
=> Mail::Message
inbound_email.mail
=> #<Mail::Message:41200>
ActionMailbox::InboundEmail
What Get’s Created
mail = Mail.new do
from 'mikel@test.lindsaar.net'
to 'you@test.lindsaar.net'
subject 'This is a test email'
body File.read('body.txt')
end
bounce_with(message) or bounce_now_with(message)
Mailboxes
Processing Emails
bounce_with(message)
bounce_now_with(message)
class SupportMailbox < ApplicationMailbox
before_processing :ensure_user
...
def ensure_user
@user = User.find_by(email: from_email)
unless @user
bounce_with Mailer.post_not_found(mail)
end
end
end
Mailboxes
Processing Emails
# Enqueues the given +message+ for delivery and changes the inbound email's status to
+:bounced+.
def bounce_with(message)
inbound_email.bounced!
message.deliver_later
end
# Immediately sends the given +message+ and changes the inbound email's status to +:bounced+.
def bounce_now_with(message)
inbound_email.bounced!
message.deliver_now
end
Mailboxes
Process Method
def create_legacy_document
legacy_document = LegacyDocument.new(
name: mail.subject,
email: mail.from.first,
)
legacy_document.save!
end
end
Reason #5
Deploying to production is
simple
Deploying to Production
Potential Pitfalls
• Default URL isn’t going to be set by default (that happens in the Application
Controller). You have to set this the same way you set it for your emails.
• Routing all your inbound email through a subdomain can save a lot of
headaches.
Default Ingress Options
• Exim
• Mailgun
• Mandrill
• Post x
• Postmark (we’ll cover this one)
• Qmail
• SendGrid
fi
Deploying
Con gure Ingress
# config/environments/production.rb
config.action_mailbox.ingress = :postmark
https://actionmailbox:PASSWORD@example.com/rails/action_mailbox/postmark/inbound_emails
Deploying
Checking the Webhook URL
Deploying
Update DNS records
THANK YOU!!!
codynorman.com
@cnorm35