Record Class MailerSpec

java.lang.Object
java.lang.Record
io.leandev.appfuse.mail.MailerSpec
Record Components:
id - 快取鍵;消費端的設定識別,同一範圍內唯一
revision - 內容指紋;變更即觸發重建
transport - 傳輸方式
smtp - SMTP 連線與認證(transport = SMTP 必填;OAUTH2 亦需 host/port)
oauth2 - OAuth2 認證(transport = OAUTH2 必填)
fromAddress - 寄件位址
fromName - 寄件顯示名稱;空則只用位址
noticeSubjectPrefix - 外寄郵件主旨前綴;空則沿用環境政策預設(MailOutboundPolicy

public record MailerSpec(String id, String revision, MailerSpec.Transport transport, MailerSpec.Smtp smtp, MailerSpec.OAuth2 oauth2, String fromAddress, String fromName, String noticeSubjectPrefix) extends Record

建立一個 DirectMailer 所需的最小資料

這個型別存在的理由

郵件能力的任務是簡化消費端的實作,不是替消費端決定郵件設定要怎麼存。框架只宣告 「我需要什麼」——持久化形狀、表結構、租戶性、CRUD、授權全由消費端決定,經 MailerSpecProvider 交出本型別即可。

框架因此不含任何 entity,連帶對隔離取向完全中性(租戶與否是消費端在自己 entity 上的決定)。

這裡刻意沒有的東西

防火牆、白名單、debug 不在 spec——它們回答的是「這個環境能不能寄到真實收件者」, 與「是誰在寄」無關,故屬環境設定、由 MailOutboundPolicy 對所有 Mailer 一律套用。 放進 spec 曾造成一個安全漏洞:每個範圍各自帶預設關閉的防火牆值,繞過環境層 宣告的「不會默默全寄」保證(見 MailOutboundPolicy 的類別註解)。

revision 是什麼、為什麼要有

內容指紋——lastModifiedDate@Version、或任何「內容變了就會變」的值皆可。

RoutingMailerid 為快取鍵、以 revision 判定是否需要重建。這讓消費端不必在每次 異動後記得清快取——那是典型「忘了就靜默用舊憑證寄信、要等寄不出去才發現」的陷阱。 消費端只要保證「內容變 → revision 變」,其餘框架負責。

成本為零:解析本來就每次都問一次 provider,快取省的是 Mailer 的建構、不是查詢。

  • Constructor Details

  • Method Details

    • from

      public String from()
      寄件者字串:有顯示名稱則 Name <addr>,否則只有位址
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • id

      public String id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • revision

      public String revision()
      Returns the value of the revision record component.
      Returns:
      the value of the revision record component
    • transport

      public MailerSpec.Transport transport()
      Returns the value of the transport record component.
      Returns:
      the value of the transport record component
    • smtp

      public MailerSpec.Smtp smtp()
      Returns the value of the smtp record component.
      Returns:
      the value of the smtp record component
    • oauth2

      public MailerSpec.OAuth2 oauth2()
      Returns the value of the oauth2 record component.
      Returns:
      the value of the oauth2 record component
    • fromAddress

      public String fromAddress()
      Returns the value of the fromAddress record component.
      Returns:
      the value of the fromAddress record component
    • fromName

      public String fromName()
      Returns the value of the fromName record component.
      Returns:
      the value of the fromName record component
    • noticeSubjectPrefix

      public String noticeSubjectPrefix()
      Returns the value of the noticeSubjectPrefix record component.
      Returns:
      the value of the noticeSubjectPrefix record component