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:
  • 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 a Email record class.
      Parameters:
      from - the value for the from record component
      fromName - the value for the fromName record component
      to - the value for the to record component
      cc - the value for the cc record component
      bcc - the value for the bcc record component
      subject - the value for the subject record component
      content - the value for the content record component
      html - the value for the html record component
      textContent - the value for the textContent record component
      attachments - the value for the attachments record component
      headers - the value for the headers record component
      replyTo - the value for the replyTo record component
      priority - the value for the priority record component
  • Method Details

    • builder

      public static Email.Builder builder()
      Create a new builder 创建新的构建器
      Returns:
      the 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

      public List<String> getAllRecipients()
      Get all recipients (to + cc + bcc) 获取所有收件人
      Returns:
      all recipient addresses | 所有收件人地址
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      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.
    • from

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

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

      public List<String> to()
      Returns the value of the to record component.
      Returns:
      the value of the to record component
    • cc

      public List<String> cc()
      Returns the value of the cc record component.
      Returns:
      the value of the cc record component
    • bcc

      public List<String> bcc()
      Returns the value of the bcc record component.
      Returns:
      the value of the bcc record component
    • subject

      public String subject()
      Returns the value of the subject record component.
      Returns:
      the value of the subject record component
    • content

      public String content()
      Returns the value of the content record component.
      Returns:
      the value of the content record component
    • html

      public boolean html()
      Returns the value of the html record component.
      Returns:
      the value of the html record component
    • textContent

      public String textContent()
      Returns the value of the textContent record component.
      Returns:
      the value of the textContent record component
    • attachments

      public List<Attachment> attachments()
      Returns the value of the attachments record component.
      Returns:
      the value of the attachments record component
    • headers

      public Map<String,String> headers()
      Returns the value of the headers record component.
      Returns:
      the value of the headers record component
    • replyTo

      public String replyTo()
      Returns the value of the replyTo record component.
      Returns:
      the value of the replyTo record component
    • priority

      public Email.Priority priority()
      Returns the value of the priority record component.
      Returns:
      the value of the priority record component