Class SmtpEmailSender

java.lang.Object
cloud.opencode.base.email.sender.SmtpEmailSender

public class SmtpEmailSender extends Object
SMTP Email Sender SMTP邮件发送器

Email sender implementation using SMTP/SMTPS protocol.

使用SMTP/SMTPS协议的邮件发送器实现。

Features | 主要功能:

  • SMTP/SMTPS/STARTTLS support - SMTP/SMTPS/STARTTLS支持
  • Authentication support - 认证支持
  • Attachments and inline images - 附件和内嵌图片
  • HTML and plain text content - HTML和纯文本内容
  • Custom headers - 自定义邮件头

Usage Examples | 使用示例:

// Basic authentication
EmailConfig config = EmailConfig.builder()
    .host("smtp.example.com")
    .port(587)
    .username("user@example.com")
    .password("password")
    .starttls(true)
    .build();

// OAuth2 authentication (Gmail/Outlook)
EmailConfig oauthConfig = EmailConfig.builder()
    .host("smtp.gmail.com")
    .port(587)
    .username("user@gmail.com")
    .oauth2Token(accessToken)
    .starttls(true)
    .build();

SmtpEmailSender sender = new SmtpEmailSender(config);
sender.send(email);

Security | 安全性:

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

    • SmtpEmailSender

      public SmtpEmailSender(EmailConfig config)
      Create SMTP sender with configuration 使用配置创建SMTP发送器
      Parameters:
      config - the email configuration | 邮件配置
  • Method Details

    • send

      public void send(Email email)
    • sendWithResult

      public SendResult sendWithResult(Email email)
    • getConfig

      public EmailConfig getConfig()
      Get email configuration 获取邮件配置
      Returns:
      the configuration | 配置
    • getSession

      public jakarta.mail.Session getSession()
      Get mail session 获取邮件会话
      Returns:
      the session | 会话
    • close

      default void close()
      Close the sender and release resources 关闭发送器并释放资源