Class Email.Builder

java.lang.Object
cloud.opencode.base.email.Email.Builder
Enclosing class:
Email

public static class Email.Builder extends Object
Email Builder 邮件构建器
Since:
JDK 25, opencode-base-email V1.0.0
Author:
Leon Soo www.LeonSoo.com
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • from

      public Email.Builder from(String from)
      Set sender email address 设置发件人邮箱地址
      Parameters:
      from - the sender email | 发件人邮箱
      Returns:
      this builder | 构建器
    • from

      public Email.Builder from(String from, String name)
      Set sender email address with display name 设置发件人邮箱地址和显示名称
      Parameters:
      from - the sender email | 发件人邮箱
      name - the display name | 显示名称
      Returns:
      this builder | 构建器
    • to

      public Email.Builder to(String... addresses)
      Add recipient email addresses 添加收件人邮箱地址
      Parameters:
      addresses - the recipient emails | 收件人邮箱
      Returns:
      this builder | 构建器
    • to

      public Email.Builder to(Collection<String> addresses)
      Add recipient email addresses from collection 从集合添加收件人邮箱地址
      Parameters:
      addresses - the recipient emails | 收件人邮箱
      Returns:
      this builder | 构建器
    • cc

      public Email.Builder cc(String... addresses)
      Add CC recipient email addresses 添加抄送收件人邮箱地址
      Parameters:
      addresses - the CC emails | 抄送邮箱
      Returns:
      this builder | 构建器
    • cc

      public Email.Builder cc(Collection<String> addresses)
      Add CC recipient email addresses from collection 从集合添加抄送收件人邮箱地址
      Parameters:
      addresses - the CC emails | 抄送邮箱
      Returns:
      this builder | 构建器
    • bcc

      public Email.Builder bcc(String... addresses)
      Add BCC recipient email addresses 添加密送收件人邮箱地址
      Parameters:
      addresses - the BCC emails | 密送邮箱
      Returns:
      this builder | 构建器
    • bcc

      public Email.Builder bcc(Collection<String> addresses)
      Add BCC recipient email addresses from collection 从集合添加密送收件人邮箱地址
      Parameters:
      addresses - the BCC emails | 密送邮箱
      Returns:
      this builder | 构建器
    • subject

      public Email.Builder subject(String subject)
      Set email subject 设置邮件主题
      Parameters:
      subject - the subject | 主题
      Returns:
      this builder | 构建器
    • text

      public Email.Builder text(String content)
      Set plain text content 设置纯文本内容
      Parameters:
      content - the text content | 文本内容
      Returns:
      this builder | 构建器
    • html

      public Email.Builder html(String content)
      Set HTML content 设置HTML内容
      Parameters:
      content - the HTML content | HTML内容
      Returns:
      this builder | 构建器
    • textAndHtml

      public Email.Builder textAndHtml(String text, String htmlContent)
      Set both plain text and HTML content (multipart/alternative) 同时设置纯文本和HTML内容(multipart/alternative)

      The email client will choose the best format to display. HTML-capable clients show HTML, plain text clients show text.

      邮件客户端会选择最佳格式显示。支持HTML的客户端显示HTML,纯文本客户端显示文本。

      Parameters:
      text - the plain text content | 纯文本内容
      htmlContent - the HTML content | HTML内容
      Returns:
      this builder | 构建器
    • attach

      public Email.Builder attach(Attachment attachment)
      Add attachment 添加附件
      Parameters:
      attachment - the attachment | 附件
      Returns:
      this builder | 构建器
    • attach

      public Email.Builder attach(Path file)
      Add file attachment 添加文件附件
      Parameters:
      file - the file path | 文件路径
      Returns:
      this builder | 构建器
    • attachAll

      public Email.Builder attachAll(Collection<Attachment> attachments)
      Add multiple attachments 添加多个附件
      Parameters:
      attachments - the attachments | 附件列表
      Returns:
      this builder | 构建器
    • header

      public Email.Builder header(String name, String value)
      Add custom header 添加自定义邮件头
      Parameters:
      name - the header name | 邮件头名称
      value - the header value | 邮件头值
      Returns:
      this builder | 构建器
    • headers

      public Email.Builder headers(Map<String,String> headers)
      Add multiple custom headers 添加多个自定义邮件头
      Parameters:
      headers - the headers | 邮件头
      Returns:
      this builder | 构建器
    • replyTo

      public Email.Builder replyTo(String replyTo)
      Set reply-to address 设置回复地址
      Parameters:
      replyTo - the reply-to email | 回复邮箱
      Returns:
      this builder | 构建器
    • priority

      public Email.Builder priority(Email.Priority priority)
      Set email priority 设置邮件优先级
      Parameters:
      priority - the priority | 优先级
      Returns:
      this builder | 构建器
    • build

      public Email build()
      Build the email 构建邮件
      Returns:
      the email | 邮件
      Throws:
      EmailException - if validation fails | 验证失败时抛出