Interface Attachment

All Known Implementing Classes:
ByteArrayAttachment, FileAttachment, InlineAttachment

public interface Attachment
Email Attachment Interface 邮件附件接口

Interface for email attachments with different sources.

支持不同来源的邮件附件接口。

Features | 主要功能:

  • File attachments - 文件附件
  • Byte array attachments - 字节数组附件
  • Inline attachments for HTML - HTML内嵌附件

Implementations | 实现类:

Usage Examples | 使用示例:

Attachment file = new FileAttachment(Path.of("report.pdf"));
Attachment bytes = new ByteArrayAttachment("data.csv", csvBytes);
Attachment inline = InlineAttachment.of("logo", Path.of("logo.png"), "image/png");

Security | 安全性:

  • Thread-safe: Implementation dependent - 线程安全: 取决于实现
  • Null-safe: No - 空值安全: 否
Since:
JDK 25, opencode-base-email V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default String
    Get Content-ID for inline attachments 获取内嵌附件的Content-ID
    Get attachment MIME type 获取附件MIME类型
    Get attachment file name 获取附件文件名
    Get attachment data as input stream 获取附件数据输入流
    long
    Get attachment size in bytes 获取附件大小(字节)
    default boolean
    Check if attachment is inline (for HTML embedding) 检查附件是否为内嵌(用于HTML嵌入)
  • Method Details

    • getFileName

      String getFileName()
      Get attachment file name 获取附件文件名
      Returns:
      the file name | 文件名
    • getContentType

      String getContentType()
      Get attachment MIME type 获取附件MIME类型
      Returns:
      the MIME type | MIME类型
    • getInputStream

      InputStream getInputStream()
      Get attachment data as input stream 获取附件数据输入流
      Returns:
      the input stream | 输入流
    • getSize

      long getSize()
      Get attachment size in bytes 获取附件大小(字节)
      Returns:
      the size in bytes | 字节大小
    • isInline

      default boolean isInline()
      Check if attachment is inline (for HTML embedding) 检查附件是否为内嵌(用于HTML嵌入)
      Returns:
      true if inline | 内嵌返回true
    • getContentId

      default String getContentId()
      Get Content-ID for inline attachments 获取内嵌附件的Content-ID
      Returns:
      the content ID or null | Content-ID或null