class ActionMailbox::Ingresses::Mailgun::InboundEmailsController
https://example.com/rails/action_mailbox/mailgun/inbound_emails/mime
.
If your application lived at https://example.com
, you would specify the fully-qualified URL
to forward inbound emails to /rails/action_mailbox/mailgun/inbound_emails/mime
.
3. {Configure Mailgun}[https://documentation.mailgun.com/en/latest/user_manual.html#receiving-forwarding-and-storing-messages]
config.action_mailbox.ingress = :mailgun
# config/environments/production.rb
2. Tell Action Mailbox to accept emails from Mailgun:
Alternatively, provide your API key in the MAILGUN_INGRESS_API_KEY
environment variable.
mailgun_api_key: …
action_mailbox:action_mailbox.mailgun_api_key
, where Action Mailbox will automatically find it:
Use rails credentials:edit
to add your API key to your application’s encrypted credentials under
so it can authenticate requests to the Mailgun ingress.
1. Give Action Mailbox your {Mailgun API key}[https://help.mailgun.com/hc/en-us/articles/203380100-Where-can-I-find-my-API-key-and-SMTP-credentials-]
== Usage
the Active Storage service, or the Active Job backend is misconfigured or unavailable
- 500 Server Error
if the Mailgun 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 Mailgun
- 401 Unauthorized
if the request’s signature could not be validated, or if its timestamp is more than 2 minutes old
- 204 No Content
if an inbound email is successfully recorded and enqueued for routing to the appropriate mailbox
Returns:
Authenticates requests by validating their signatures.
- signature
: A hexadecimal HMAC-SHA256 of the timestamp concatenated with the token, generated using the Mailgun API key
- token
: A randomly-generated, 50-character string
- timestamp
: The current time according to Mailgun as the number of seconds passed since the UNIX epoch
- body-mime
: The full RFC 822 message
Ingests inbound emails from Mailgun. Requires the following parameters:
def authenticate
def authenticate head :unauthorized unless authenticated? end
def authenticated?
def authenticated? if key.present? Authenticator.new( key: key, timestamp: params.require(:timestamp), token: params.require(:token), signature: params.require(:signature) ).authenticated? else raise ArgumentError, <<~MESSAGE.squish Missing required Mailgun API key. Set action_mailbox.mailgun_api_key in your application's encrypted credentials or provide the MAILGUN_INGRESS_API_KEY environment variable. MESSAGE end end
def create
def create ActionMailbox::InboundEmail.create_and_extract_message_id! params.require("body-mime") end
def key
def key Rails.application.credentials.dig(:action_mailbox, :mailgun_api_key) || ENV["MAILGUN_INGRESS_API_KEY"] end