Add inbound email

This commit is contained in:
David Heinemeier Hansson 2018-09-17 16:55:07 -07:00
parent 52b1e2c6cf
commit 627bbd34e1
3 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,17 @@
class ActionMailbox::InboundEmail < ActiveRecord::Base
self.table_name = "action_mailbox_inbound_email"
after_create_commit :deliver_to_mailroom_later
has_one_attached :raw_message
enum status: %i[ pending processing delivered failed bounced ]
def mail
@mail ||= Mail.new(Mail::Utilities.binary_unsafe_to_crlf(raw_message.download))
end
private
def deliver_to_mailroom_later
ActionMailbox::DeliverInboundEmailToMailroomJob.perform_later self
end
end

View File

@ -0,0 +1,10 @@
class ActionMailbox::DeliverInboundEmailToMailroomJob < ApplicationJob
queue_as :action_mailbox_inbound_email
# Occasional `SSL_read: decryption failed or bad record mac` that resolve on retry
retry_on OpenSSL::SSL::SSLError
def perform(inbound_email)
ApplicationMailbox.receive inbound_email
end
end

View File

@ -0,0 +1,10 @@
class CreateActionMailboxTables < ActiveRecord::Migration[5.2]
def change
create_table :action_mailbox_inbound_emails do |t|
t.integer :status, default: 0, null: false
t.datetime :created_at, precision: 6
t.datetime :updated_at, precision: 6
end
end
end