Record Class Email
java.lang.Object
java.lang.Record
cloud.opencode.base.email.Email
public record Email(String from, String fromName, List<String> to, List<String> cc, List<String> bcc, String subject, String content, boolean html, String textContent, List<Attachment> attachments, Map<String,String> headers, String replyTo, Email.Priority priority)
extends Record
Email Entity Record
邮件实体记录
Immutable email entity containing all email properties.
包含所有邮件属性的不可变邮件实体。
Features | 主要功能:
- Fluent builder pattern - 流畅的构建器模式
- Multiple recipients support (to/cc/bcc) - 多收件人支持
- HTML and plain text content - HTML和纯文本内容
- Attachment support - 附件支持
- Custom headers - 自定义邮件头
- Priority levels - 优先级
Usage Examples | 使用示例:
// Simple text email
Email email = Email.builder()
.from("sender@example.com")
.to("recipient@example.com")
.subject("Hello")
.text("Hello World!")
.build();
// HTML email with attachment
Email email = Email.builder()
.from("sender@example.com", "Sender Name")
.to("user1@example.com", "user2@example.com")
.cc("manager@example.com")
.subject("Monthly Report")
.html("<h1>Report</h1><p>See attachment</p>")
.attach(Path.of("report.pdf"))
.priority(Email.Priority.HIGH)
.build();
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-email V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classEmail Builder 邮件构建器static enumEmail priority levels 邮件优先级 -
Constructor Summary
ConstructorsConstructorDescriptionEmail(String from, String fromName, List<String> to, List<String> cc, List<String> bcc, String subject, String content, boolean html, String textContent, List<Attachment> attachments, Map<String, String> headers, String replyTo, Email.Priority priority) Creates an instance of aEmailrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theattachmentsrecord component.bcc()Returns the value of thebccrecord component.static Email.Builderbuilder()Create a new builder 创建新的构建器cc()Returns the value of theccrecord component.content()Returns the value of thecontentrecord component.final booleanIndicates whether some other object is "equal to" this one.from()Returns the value of thefromrecord component.fromName()Returns the value of thefromNamerecord component.Get all recipients (to + cc + bcc) 获取所有收件人booleanCheck if email has both text and HTML content (multipart/alternative) 检查邮件是否同时有文本和HTML内容booleanCheck if email has attachments 检查邮件是否有附件final inthashCode()Returns a hash code value for this object.booleanCheck if email has inline attachments 检查邮件是否有内嵌附件headers()Returns the value of theheadersrecord component.booleanhtml()Returns the value of thehtmlrecord component.priority()Returns the value of thepriorityrecord component.replyTo()Returns the value of thereplyTorecord component.subject()Returns the value of thesubjectrecord component.Returns the value of thetextContentrecord component.to()Returns the value of thetorecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
Email
public Email(String from, String fromName, List<String> to, List<String> cc, List<String> bcc, String subject, String content, boolean html, String textContent, List<Attachment> attachments, Map<String, String> headers, String replyTo, Email.Priority priority) Creates an instance of aEmailrecord class.- Parameters:
from- the value for thefromrecord componentfromName- the value for thefromNamerecord componentto- the value for thetorecord componentcc- the value for theccrecord componentbcc- the value for thebccrecord componentsubject- the value for thesubjectrecord componentcontent- the value for thecontentrecord componenthtml- the value for thehtmlrecord componenttextContent- the value for thetextContentrecord componentattachments- the value for theattachmentsrecord componentheaders- the value for theheadersrecord componentreplyTo- the value for thereplyTorecord componentpriority- the value for thepriorityrecord component
-
-
Method Details
-
builder
-
hasAttachments
public boolean hasAttachments()Check if email has attachments 检查邮件是否有附件- Returns:
- true if has attachments | 有附件返回true
-
hasAlternativeContent
public boolean hasAlternativeContent()Check if email has both text and HTML content (multipart/alternative) 检查邮件是否同时有文本和HTML内容- Returns:
- true if has alternative content | 有备选内容返回true
-
hasInlineAttachments
public boolean hasInlineAttachments()Check if email has inline attachments 检查邮件是否有内嵌附件- Returns:
- true if has inline attachments | 有内嵌附件返回true
-
getAllRecipients
-
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. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
from
Returns the value of thefromrecord component.- Returns:
- the value of the
fromrecord component
-
fromName
Returns the value of thefromNamerecord component.- Returns:
- the value of the
fromNamerecord component
-
to
-
cc
-
bcc
-
subject
Returns the value of thesubjectrecord component.- Returns:
- the value of the
subjectrecord component
-
content
Returns the value of thecontentrecord component.- Returns:
- the value of the
contentrecord component
-
html
public boolean html()Returns the value of thehtmlrecord component.- Returns:
- the value of the
htmlrecord component
-
textContent
Returns the value of thetextContentrecord component.- Returns:
- the value of the
textContentrecord component
-
attachments
Returns the value of theattachmentsrecord component.- Returns:
- the value of the
attachmentsrecord component
-
headers
-
replyTo
Returns the value of thereplyTorecord component.- Returns:
- the value of the
replyTorecord component
-
priority
Returns the value of thepriorityrecord component.- Returns:
- the value of the
priorityrecord component
-