class ActionMailbox::Ingresses::Mandrill::InboundEmailsController
the Active Storage service, or the Active Job backend is misconfigured or unavailable
- 500 Server Error
if the Mandrill API key is missing, or one of the Active Record database,
- 422 Unprocessable Entity
if the request is missing required parameters
- 404 Not Found
if Action Mailbox is not configured to accept inbound emails from Mandrill
- 401 Unauthorized
if the request’s signature could not be validated
- 204 No Content
if an inbound email is successfully recorded and enqueued for routing to the appropriate mailbox
Returns:
Each event is expected to have a msg
object containing a full RFC 822 message in its raw_msg
property.
Requires a mandrill_events
parameter containing a JSON array of Mandrill inbound email event objects.
Ingests inbound emails from Mandrill.
def authenticate
def authenticate head :unauthorized unless authenticated? end
def authenticated?
def authenticated? if key.present? Authenticator.new(request, key).authenticated? else raise ArgumentError, <<~MESSAGE.squish Missing required Mandrill API key. Set action_mailbox.mandrill_api_key in your application's encrypted credentials or provide the MANDRILL_INGRESS_API_KEY environment variable. MESSAGE end end
def create
def create raw_emails.each { |raw_email| ActionMailbox::InboundEmail.create_and_extract_message_id! raw_email } head :ok rescue JSON::ParserError => error logger.error error.message head :unprocessable_entity end
def events
def events JSON.parse params.require(:mandrill_events) end
def health_check
def health_check head :ok end
def key
def key Rails.application.credentials.dig(:action_mailbox, :mandrill_api_key) || ENV["MANDRILL_INGRESS_API_KEY"] end
def raw_emails
def raw_emails events.select { |event| event["event"] == "inbound" }.collect { |event| event.dig("msg", "raw_msg") } end