Class InlineAttachment

java.lang.Object
cloud.opencode.base.email.attachment.InlineAttachment
All Implemented Interfaces:
Attachment

public final class InlineAttachment extends Object implements Attachment
Inline Email Attachment for HTML Embedding 用于HTML嵌入的内嵌邮件附件

Attachment implementation for inline content in HTML emails.

HTML邮件中内嵌内容的附件实现。

Features | 主要功能:

  • Content-ID for HTML reference - 用于HTML引用的Content-ID
  • Image embedding support - 图片嵌入支持
  • Use with cid: URLs in HTML - 在HTML中使用cid:URL

Usage Examples | 使用示例:

// Create inline image
InlineAttachment logo = InlineAttachment.of("logo", Path.of("logo.png"), "image/png");

// Reference in HTML
String html = "<img src=\"cid:logo\" alt=\"Logo\"/>";

Email email = Email.builder()
    .html(html)
    .attach(logo)
    .build();

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Immutable: Yes - 不可变: 是
Since:
JDK 25, opencode-base-email V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • InlineAttachment

      public InlineAttachment(String contentId, String fileName, byte[] data, String contentType)
      Create inline attachment from byte data 从字节数据创建内嵌附件
      Parameters:
      contentId - the Content-ID for HTML reference | 用于HTML引用的Content-ID
      fileName - the file name | 文件名
      data - the byte data | 字节数据
      contentType - the MIME type | MIME类型
  • Method Details

    • of

      public static InlineAttachment of(String contentId, Path path, String contentType)
      Create inline attachment from file 从文件创建内嵌附件
      Parameters:
      contentId - the Content-ID for HTML reference | 用于HTML引用的Content-ID
      path - the file path | 文件路径
      contentType - the MIME type | MIME类型
      Returns:
      the inline attachment | 内嵌附件
    • of

      public static InlineAttachment of(String contentId, String fileName, byte[] data, String contentType)
      Create inline attachment from byte data 从字节数据创建内嵌附件
      Parameters:
      contentId - the Content-ID for HTML reference | 用于HTML引用的Content-ID
      fileName - the file name | 文件名
      data - the byte data | 字节数据
      contentType - the MIME type | MIME类型
      Returns:
      the inline attachment | 内嵌附件
    • getFileName

      public String getFileName()
      Description copied from interface: Attachment
      Get attachment file name 获取附件文件名
      Specified by:
      getFileName in interface Attachment
      Returns:
      the file name | 文件名
    • getContentType

      public String getContentType()
      Description copied from interface: Attachment
      Get attachment MIME type 获取附件MIME类型
      Specified by:
      getContentType in interface Attachment
      Returns:
      the MIME type | MIME类型
    • getInputStream

      public InputStream getInputStream()
      Description copied from interface: Attachment
      Get attachment data as input stream 获取附件数据输入流
      Specified by:
      getInputStream in interface Attachment
      Returns:
      the input stream | 输入流
    • getSize

      public long getSize()
      Description copied from interface: Attachment
      Get attachment size in bytes 获取附件大小(字节)
      Specified by:
      getSize in interface Attachment
      Returns:
      the size in bytes | 字节大小
    • isInline

      public boolean isInline()
      Description copied from interface: Attachment
      Check if attachment is inline (for HTML embedding) 检查附件是否为内嵌(用于HTML嵌入)
      Specified by:
      isInline in interface Attachment
      Returns:
      true if inline | 内嵌返回true
    • getContentId

      public String getContentId()
      Description copied from interface: Attachment
      Get Content-ID for inline attachments 获取内嵌附件的Content-ID
      Specified by:
      getContentId in interface Attachment
      Returns:
      the content ID or null | Content-ID或null
    • getData

      public byte[] getData()
      Get a copy of the byte data 获取字节数据的拷贝
      Returns:
      copy of the data | 数据拷贝
    • toString

      public String toString()
      Overrides:
      toString in class Object