Class: MainMailbox

Inherits:
ApplicationMailbox
  • Object
show all
Defined in:
lib/generators/cloudflare/email/templates/main_mailbox.rb

Overview

Scaffolded by ‘bin/rails cloudflare:email:install` as the default landing place for inbound Cloudflare email. Replace the `process` body with your real handling — parse the subject, match the sender, hand off to a job, etc.

See guides.rubyonrails.org/action_mailbox_basics.html for the full ActionMailbox API (mail is a Mail::Message, inbound_email is the AR record).

Instance Method Summary collapse

Instance Method Details

#processObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/cloudflare/email/templates/main_mailbox.rb', line 8

def process
  Rails.logger.info(
    "[cloudflare-email] inbound received: " \
    "from=#{mail.from&.first.inspect} " \
    "to=#{Array(mail.to).inspect} " \
    "subject=#{mail.subject.inspect} " \
    "message_id=#{mail.message_id.inspect}"
  )

  # Example ways to pull content out of the incoming message:
  #
  #   mail.from.first              # => "alice@example.com"
  #   mail.to                      # => ["cole@in.rebulk.com"]
  #   mail.subject                 # => "Re: agent task"
  #   mail.body.decoded            # => "text/plain body, decoded"
  #   mail.html_part&.body&.decoded
  #   mail.attachments             # => [Mail::Part, ...]
  #   inbound_email.message_id     # => "<...@mail.gmail.com>"
  #   inbound_email.raw_email.download  # full RFC822 bytes
  #
  # Common next steps:
  #   YourAgentJob.perform_later(mail.from.first, mail.body.decoded)
  #   bounce_with BounceMailer.not_recognized(inbound_email) if ignore?
end