略過內容 略過搜尋

從 Mailgun 輸入收到的電子郵件。需要以下參數

  • body-mime:完整的 RFC 822 訊息

  • timestamp:Mailgun 根據 UNIX 紀元所經過的秒數當前時間

  • token:隨機產生的 50 字元字串

  • signature:使用 Mailgun 簽章金鑰產生的時間戳記與令牌串接的十六進位 HMAC-SHA256

驗證個別請求簽章來驗證請求。

傳回值

  • 如果已成功記錄收到的電子郵件,並排入佇列,準備傳遞至適當的信箱,則204 無內容

  • 如果無法驗證請求的簽章,或者其時間戳記超過 2 分鐘,則401 未授權

  • 如果 Action Mailbox 未設定為接受來自 Mailgun 的收件電子郵件,則404 未找到

  • 如果請求遺漏必要的參數,則422 無法處理的實體

  • 如果遺漏 Mailgun 簽章金鑰,或者 Active Record 資料庫、Active Storage 服務或 Active Job 後端設定錯誤或無法使用,則500 伺服器錯誤

用法

  1. 提供 Mailgun 簽章金鑰給 Action Mailbox(你可在 Mailgun 的「設定」->「安全性與使用者」->「API 安全性」中找到該金鑰),以便驗證寄往 Mailgun 入口的請求。

    使用 bin/rails credentials:edit,將你的簽章金鑰加入至 action_mailbox.mailgun_signing_key 應用程式加密憑證中,Action Mailbox 會自動在此處尋找該金鑰

    action_mailbox:
      mailgun_signing_key: ...
    

    或者,在 MAILGUN_INGRESS_SIGNING_KEY 環境變數中提供你的簽章金鑰。

  2. 指示 Action Mailbox 接受來自 Mailgun 的郵件

    # config/environments/production.rb
    config.action_mailbox.ingress = :mailgun
    
  3. 設定 Mailgun,將收到的電子郵件轉寄至 /rails/action_mailbox/mailgun/inbound_emails/mime

    如果你的應用程式存在於 https://example.com,你應指定完整限定網址 https://example.com/rails/action_mailbox/mailgun/inbound_emails/mime

命名空間
方法
C

執行個體公用方法

建立()

# File actionmailbox/app/controllers/action_mailbox/ingresses/mailgun/inbound_emails_controller.rb, line 49
def create
  ActionMailbox::InboundEmail.create_and_extract_message_id! mail
end