跳到內容 跳到搜尋

InboundEmail 是 Active Record,它會保留指向儲存在 Active Storage 中的原始電子郵件的參考,並追蹤處理的狀態。預設情況下,接收的電子郵件將會經歷下列生命週期

  • 待處理: 剛剛由其中一個進入控制器接收,並排定路由。

  • 處理中: 處理期間,當特定的信箱執行其 process 方法時。

  • 已傳送: 已由特定信箱成功處理。

  • 失敗: 在特定信箱執行 #process 方法時引發例外。

  • 退信: 已特定信箱拒絕處理,並退回給寄件者。

InboundEmail 到達狀態 deliveredfailedbounced 時,將會計為 #processed?。處理完後, InboundEmail 將會排定於稍後自動銷毀。

當處理 InboundEmail 時,你通常會與來源的解析版本互動,這個版本會以 Mail 物件的形式從 #mail 取得。不過你也可以使用 #source 方法直接存取原始來源。

範例

inbound_email.mail.from # => 'david@loudthinking.com'
inbound_email.source # Returns the full rfc822 source of the email as text
命名空間
方法
M
P
S

實例公開方法

mail()

# File actionmailbox/app/models/action_mailbox/inbound_email.rb, line 33
def mail
  @mail ||= Mail.from_source(source)
end

processed?()

# File actionmailbox/app/models/action_mailbox/inbound_email.rb, line 41
def processed?
  delivered? || failed? || bounced?
end

source()

# File actionmailbox/app/models/action_mailbox/inbound_email.rb, line 37
def source
  @source ||= raw_email.download
end