Class MimeBuilder
java.lang.Object
cloud.opencode.base.email.protocol.mime.MimeBuilder
MIME Message Builder
MIME 消息构建器
Builds a complete RFC 2822 MIME message as a raw string, including
all headers and a properly structured multipart body. This class replaces
Jakarta Mail's MimeMessage, MimeMultipart, and MimeBodyPart.
构建完整的 RFC 2822 MIME 消息原始字符串,包括所有邮件头和正确结构化的
multipart 消息体。此类替代 Jakarta Mail 的 MimeMessage、MimeMultipart
和 MimeBodyPart。
Features | 主要功能:
- Plain text and HTML content - 纯文本和HTML内容
- Multipart/alternative (text + HTML) - 多部分/备选(文本+HTML)
- Regular and inline attachments - 常规和内嵌附件
- RFC 2047 encoded headers for non-ASCII - RFC 2047 编码非ASCII邮件头
- RFC 2822 date formatting - RFC 2822 日期格式化
- X-Priority support - X-Priority 支持
- Custom headers - 自定义邮件头
Message Structure | 消息结构:
Case 1: text only → text/plain
Case 2: HTML only → text/html
Case 3: text + HTML → multipart/alternative { text, html }
Case 4: + attachments → multipart/mixed { body, attachments... }
Case 5: + inline + HTML → multipart/related { html, inline... }
Case 6: all combined → multipart/mixed {
multipart/related {
multipart/alternative { text, html },
inline...
},
attachments...
}
Security | 安全性:
- Thread-safe: Yes (stateless builder method) - 线程安全: 是(无状态构建方法)
- Null-safe: Partial (nullable parameters documented) - 空值安全: 部分
- Since:
- JDK 25, opencode-base-email V1.0.3
- Author:
- Leon Soo
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordAttachment data for building MIME messages 构建 MIME 消息的附件数据 -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbuildMessage(String from, String fromName, List<String> to, List<String> cc, List<String> bcc, String replyTo, String subject, String textContent, String htmlContent, boolean htmlFlag, String content, List<MimeBuilder.AttachmentData> attachments, Map<String, String> headers, int priority, String domain) Build a complete RFC 2822 MIME message 构建完整的 RFC 2822 MIME 消息static StringgetMessageId(String rawMessage) Extract the Message-ID from a built message 从已构建的消息中提取 Message-ID
-
Method Details
-
buildMessage
public static String buildMessage(String from, String fromName, List<String> to, List<String> cc, List<String> bcc, String replyTo, String subject, String textContent, String htmlContent, boolean htmlFlag, String content, List<MimeBuilder.AttachmentData> attachments, Map<String, String> headers, int priority, String domain) Build a complete RFC 2822 MIME message 构建完整的 RFC 2822 MIME 消息Constructs headers and body according to the content types provided. When both
textContentandhtmlContentare provided, a multipart/alternative structure is created. Attachments result in multipart/mixed wrapping.根据提供的内容类型构建邮件头和消息体。当同时提供
textContent和htmlContent时,创建 multipart/alternative 结构。附件导致 multipart/mixed 包装。- Parameters:
from- sender address ("Name <email>" or just "email") | 发件人地址fromName- sender display name (nullable, used for RFC 2047 encoding) | 发件人显示名称to- recipient addresses | 收件人地址列表cc- CC addresses (nullable) | 抄送地址列表bcc- BCC addresses (nullable) | 密送地址列表replyTo- reply-to address (nullable) | 回复地址subject- email subject | 邮件主题textContent- plain text body (nullable) | 纯文本正文htmlContent- HTML body (nullable) | HTML正文htmlFlag- true ifcontentis HTML when only one content type is used | 单一内容类型时是否为HTMLcontent- the main content string (used when textContent/htmlContent are not both set) | 主内容字符串attachments- attachment data list (nullable) | 附件数据列表headers- custom headers (nullable) | 自定义邮件头priority- X-Priority value (1=high, 3=normal, 5=low) | 优先级值domain- domain for Message-ID generation | 消息ID生成用的域名- Returns:
- the complete MIME message string | 完整的 MIME 消息字符串
-
getMessageId
-