跳至内容 跳至搜索

接收来自 Postmark 的入站电子邮件。需要一个包含完整 RFC 822 消息的 RawEmail 参数。

使用 HTTP 基本身份验证来验证请求。用户名始终是 actionmailbox,密码从应用程序的加密凭据或环境变量中读取。请参阅下面的“用法”部分。

请注意,基本身份验证在未加密的 HTTP 上是不安全的。拦截明文发送到 Postmark 入站的请求的攻击者可以窃取其密码。您应该仅在 HTTPS 上使用 Postmark 入站。

返回值

  • 204 No Content:如果入站电子邮件已成功记录并排队以路由到相应的邮箱

  • 如果请求的签名无法验证,则返回 401 Unauthorized

  • 如果 Action Mailbox 未配置为接受来自 Postmark 的入站电子邮件,则返回 404 Not Found

  • 如果请求缺少必需的 RawEmail 参数,则返回 422 Unprocessable Entity

  • 如果入站接口密码未配置,或者 Active Record 数据库、Active Storage 服务或 Active Job 后端配置错误或不可用,则返回 500 Server Error

用法

  1. 告知 Action Mailbox 接受来自 Postmark 的电子邮件。

    # config/environments/production.rb
    config.action_mailbox.ingress = :postmark
    
  2. 生成一个强密码,Action Mailbox 可以使用该密码对 Postmark 入站的请求进行身份验证。

    使用 bin/rails credentials:edit 将密码添加到应用程序的加密凭据中,位于 action_mailbox.ingress_password 下,Action Mailbox 会自动找到它。

    action_mailbox:
      ingress_password: ...

    或者,在 RAILS_INBOUND_EMAIL_PASSWORD 环境变量中提供密码。

  3. 配置 Postmark 将入站电子邮件转发到 /rails/action_mailbox/postmark/inbound_emails,用户名为 actionmailbox,密码为您之前生成的密码。如果您的应用程序位于 https://example.com,您将使用以下完全限定的 URL 配置您的 Postmark 入站 webhook:

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

    注意:配置 Postmark 入站 webhook 时,请务必勾选标有 *“在 JSON payload 中包含原始电子邮件内容”* 的复选框。Action Mailbox 需要原始电子邮件内容才能正常工作。

方法
C

实例公共方法

create()

# File actionmailbox/app/controllers/action_mailbox/ingresses/postmark/inbound_emails_controller.rb, line 51
    def create
      ActionMailbox::InboundEmail.create_and_extract_message_id! mail
    rescue ActionController::ParameterMissing => error
      logger.error <<~MESSAGE
        #{error.message}

        When configuring your Postmark inbound webhook, be sure to check the box
        labeled "Include raw email content in JSON payload".
      MESSAGE
      head ActionDispatch::Constants::UNPROCESSABLE_CONTENT
    end