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、或任何「內容變了就會變」的值皆可。
RoutingMailer 以 id 為快取鍵、以 revision 判定是否需要重建。這讓消費端不必在每次
異動後記得清快取——那是典型「忘了就靜默用舊憑證寄信、要等寄不出去才發現」的陷阱。
消費端只要保證「內容變 → revision 變」,其餘框架負責。
成本為零:解析本來就每次都問一次 provider,快取省的是 Mailer 的建構、不是查詢。
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOAuth2 認證(client_credentials)static final recordSMTP 連線static enum傳輸/認證方式 -
Constructor Summary
ConstructorsConstructorDescriptionMailerSpec(String id, String revision, MailerSpec.Transport transport, MailerSpec.Smtp smtp, MailerSpec.OAuth2 oauth2, String fromAddress, String fromName, String noticeSubjectPrefix) Creates an instance of aMailerSpecrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.from()寄件者字串:有顯示名稱則Name <addr>,否則只有位址Returns the value of thefromAddressrecord component.fromName()Returns the value of thefromNamerecord component.final inthashCode()Returns a hash code value for this object.id()Returns the value of theidrecord component.Returns the value of thenoticeSubjectPrefixrecord component.oauth2()Returns the value of theoauth2record component.revision()Returns the value of therevisionrecord component.smtp()Returns the value of thesmtprecord component.final StringtoString()Returns a string representation of this record class.Returns the value of thetransportrecord component.
-
Constructor Details
-
MailerSpec
public MailerSpec(String id, String revision, MailerSpec.Transport transport, MailerSpec.Smtp smtp, MailerSpec.OAuth2 oauth2, String fromAddress, String fromName, String noticeSubjectPrefix) Creates an instance of aMailerSpecrecord class.- Parameters:
id- the value for theidrecord componentrevision- the value for therevisionrecord componenttransport- the value for thetransportrecord componentsmtp- the value for thesmtprecord componentoauth2- the value for theoauth2record componentfromAddress- the value for thefromAddressrecord componentfromName- the value for thefromNamerecord componentnoticeSubjectPrefix- the value for thenoticeSubjectPrefixrecord component
-
-
Method Details
-
from
寄件者字串:有顯示名稱則Name <addr>,否則只有位址 -
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object). -
id
-
revision
-
transport
-
smtp
-
oauth2
-
fromAddress
Returns the value of thefromAddressrecord component.- Returns:
- the value of the
fromAddressrecord component
-
fromName
-
noticeSubjectPrefix
Returns the value of thenoticeSubjectPrefixrecord component.- Returns:
- the value of the
noticeSubjectPrefixrecord component
-