跳至內容 跳至搜尋

接收來自 SendGrid 的 inbound emails。需要一個包含完整 RFC 822 訊息的 email 參數。

使用 HTTP 基本驗證來驗證請求。使用者名稱永遠是 actionmailbox,密碼則從應用程式的加密憑證或環境變數中讀取。請參閱下方的使用說明章節。

請注意,基本驗證在未加密的 HTTP 上是不安全的。攔截到 SendGrid 入口明文請求的攻擊者可以得知其密碼。您應該只在 HTTPS 上使用 SendGrid 入口。

回傳值

  • 若 inbound email 成功記錄並排入佇列以路由到適當的信箱,則回傳 204 No Content

  • 若請求的簽章無法驗證,則回傳 401 Unauthorized

  • 若 Action Mailbox 未設定為接受來自 SendGrid 的 inbound emails,則回傳 404 Not Found

  • 若請求缺少必要的 email 參數,則回傳 422 Unprocessable Entity

  • 若未設定入口密碼,或者 Active Record 資料庫、Active Storage 服務或 Active Job 後端設定錯誤或無法使用,則回傳 500 Server Error

使用說明

  1. 設定 Action Mailbox 接收來自 SendGrid 的 emails

    # config/environments/production.rb
    config.action_mailbox.ingress = :sendgrid
    
  2. 產生 Action Mailbox 可用於驗證 SendGrid 入口請求的強式密碼。

    使用 bin/rails credentials:edit 將密碼新增到應用程式加密憑證中的 action_mailbox.ingress_password 下,Action Mailbox 會自動找到它

    action_mailbox:
      ingress_password: ...
    

    或者,在 RAILS_INBOUND_EMAIL_PASSWORD 環境變數中提供密碼。

  3. 設定 SendGrid Inbound Parse 將 inbound emails 轉發到 /rails/action_mailbox/sendgrid/inbound_emails,使用者名稱為 actionmailbox,密碼為您先前產生的密碼。如果您的應用程式位於 https://example.com,您將使用以下完整網址設定 SendGrid

    https://actionmailbox:PASSWORD@example.com/rails/action_mailbox/sendgrid/inbound_emails
    

    注意:設定 SendGrid Inbound Parse webhook 時,請務必勾選標記為 *「發佈原始、完整的 MIME 訊息」* 的核取方塊。Action Mailbox 需要原始 MIME 訊息才能運作。

方法
C

公開實體方法

create()

# File actionmailbox/app/controllers/action_mailbox/ingresses/sendgrid/inbound_emails_controller.rb, line 51
def create
  ActionMailbox::InboundEmail.create_and_extract_message_id! mail
rescue JSON::ParserError => error
  logger.error error.message
  head :unprocessable_entity
end