Class: ActionMailbox::Ingresses::Resend::InboundEmailsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/action_mailbox/ingresses/resend/inbound_emails_controller.rb

Overview

Ingests inbound emails delivered by Resend's email.received webhook.

Resend webhooks only carry the received email's metadata, so the full message (including any attachments) is fetched from the Resend API before being enqueued for routing. The webhook request is authenticated by verifying its Svix signature against the webhook's signing secret, which is stored in the action_mailbox.resend_signing_secret Rails credential or the RESEND_INGRESS_SIGNING_SECRET environment variable.

Returns:

  • 204 No Content if an inbound email is successfully recorded and enqueued for routing, or if the event is not an email.received event and was ignored
  • 401 Unauthorized if the request's signature could not be validated
  • 404 Not Found if Action Mailbox is not configured to accept inbound emails from Resend
  • 422 Unprocessable Entity if the request's payload is malformed
  • 500 Server Error if the webhook signing secret is missing, the Resend API could not be reached, or one of the Active Record database, the Active Storage service, or the Active Job backend is misconfigured or unavailable

Instance Method Summary collapse

Instance Method Details

#create ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/action_mailbox/ingresses/resend/inbound_emails_controller.rb', line 29

def create
  return head :no_content unless email_received_event?
  return head :unprocessable_entity if email_id.nil?

  ActionMailbox::InboundEmail.create_and_extract_message_id! raw_email
  head :no_content
rescue JSON::ParserError => e
  logger.error e.message
  head :unprocessable_entity
end