Class InlineAttachment
java.lang.Object
cloud.opencode.base.email.attachment.InlineAttachment
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionInlineAttachment(String contentId, String fileName, byte[] data, String contentType) Create inline attachment from byte data 从字节数据创建内嵌附件 -
Method Summary
Modifier and TypeMethodDescriptionGet Content-ID for inline attachments 获取内嵌附件的Content-IDGet attachment MIME type 获取附件MIME类型byte[]getData()Get a copy of the byte data 获取字节数据的拷贝Get attachment file name 获取附件文件名Get attachment data as input stream 获取附件数据输入流longgetSize()Get attachment size in bytes 获取附件大小(字节)booleanisInline()Check if attachment is inline (for HTML embedding) 检查附件是否为内嵌(用于HTML嵌入)static InlineAttachmentCreate inline attachment from byte data 从字节数据创建内嵌附件static InlineAttachmentCreate inline attachment from file 从文件创建内嵌附件toString()
-
Constructor Details
-
InlineAttachment
Create inline attachment from byte data 从字节数据创建内嵌附件- Parameters:
contentId- the Content-ID for HTML reference | 用于HTML引用的Content-IDfileName- the file name | 文件名data- the byte data | 字节数据contentType- the MIME type | MIME类型
-
-
Method Details
-
of
Create inline attachment from file 从文件创建内嵌附件- Parameters:
contentId- the Content-ID for HTML reference | 用于HTML引用的Content-IDpath- 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-IDfileName- the file name | 文件名data- the byte data | 字节数据contentType- the MIME type | MIME类型- Returns:
- the inline attachment | 内嵌附件
-
getFileName
Description copied from interface:AttachmentGet attachment file name 获取附件文件名- Specified by:
getFileNamein interfaceAttachment- Returns:
- the file name | 文件名
-
getContentType
Description copied from interface:AttachmentGet attachment MIME type 获取附件MIME类型- Specified by:
getContentTypein interfaceAttachment- Returns:
- the MIME type | MIME类型
-
getInputStream
Description copied from interface:AttachmentGet attachment data as input stream 获取附件数据输入流- Specified by:
getInputStreamin interfaceAttachment- Returns:
- the input stream | 输入流
-
getSize
public long getSize()Description copied from interface:AttachmentGet attachment size in bytes 获取附件大小(字节)- Specified by:
getSizein interfaceAttachment- Returns:
- the size in bytes | 字节大小
-
isInline
public boolean isInline()Description copied from interface:AttachmentCheck if attachment is inline (for HTML embedding) 检查附件是否为内嵌(用于HTML嵌入)- Specified by:
isInlinein interfaceAttachment- Returns:
- true if inline | 内嵌返回true
-
getContentId
Description copied from interface:AttachmentGet Content-ID for inline attachments 获取内嵌附件的Content-ID- Specified by:
getContentIdin interfaceAttachment- 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
-