Record Class EmailConfig
java.lang.Object
java.lang.Record
cloud.opencode.base.email.EmailConfig
public record EmailConfig(String host, int port, String username, String password, String oauth2Token, boolean ssl, boolean starttls, String defaultFrom, String defaultFromName, Duration timeout, Duration connectionTimeout, int maxRetries, int poolSize, Duration poolIdleTimeout, boolean debug, DkimConfig dkim)
extends Record
Email Configuration Record
邮件配置记录
Immutable configuration for email sending.
邮件发送的不可变配置。
Features | 主要功能:
- SMTP/SMTPS configuration - SMTP/SMTPS配置
- SSL/TLS support - SSL/TLS支持
- OAuth2 authentication (Gmail, Outlook) - OAuth2认证
- Connection pool settings - 连接池设置
- Retry configuration - 重试配置
- DKIM signing support - DKIM签名支持
Usage Examples | 使用示例:
// Basic configuration
EmailConfig config = EmailConfig.builder()
.host("smtp.example.com")
.port(587)
.username("user@example.com")
.password("password")
.starttls(true)
.defaultFrom("noreply@example.com", "System")
.build();
// SSL configuration (port 465)
EmailConfig config = EmailConfig.builder()
.host("smtp.example.com")
.port(465)
.ssl(true)
.username("user")
.password("pass")
.build();
// OAuth2 configuration (Gmail)
EmailConfig config = EmailConfig.builder()
.host("smtp.gmail.com")
.port(587)
.username("user@gmail.com")
.oauth2Token(accessToken)
.starttls(true)
.build();
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Since:
- JDK 25, opencode-base-email V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classEmail Configuration Builder 邮件配置构建器 -
Constructor Summary
ConstructorsConstructorDescriptionEmailConfig(String host, int port, String username, String password, String oauth2Token, boolean ssl, boolean starttls, String defaultFrom, String defaultFromName, Duration timeout, Duration connectionTimeout, int maxRetries, int poolSize, Duration poolIdleTimeout, boolean debug, DkimConfig dkim) Creates an instance of aEmailConfigrecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic EmailConfig.Builderbuilder()Create a new builder 创建新的构建器Returns the value of theconnectionTimeoutrecord component.booleandebug()Returns the value of thedebugrecord component.Returns the value of thedefaultFromrecord component.Returns the value of thedefaultFromNamerecord component.dkim()Returns the value of thedkimrecord component.final booleanIndicates whether some other object is "equal to" this one.booleanhasDkim()Check if DKIM signing is configured 检查是否配置了DKIM签名final inthashCode()Returns a hash code value for this object.booleanCheck if OAuth2 authentication is configured 检查是否配置了OAuth2认证host()Returns the value of thehostrecord component.intReturns the value of themaxRetriesrecord component.Returns the value of theoauth2Tokenrecord component.password()Returns the value of thepasswordrecord component.Returns the value of thepoolIdleTimeoutrecord component.intpoolSize()Returns the value of thepoolSizerecord component.intport()Returns the value of theportrecord component.booleanCheck if authentication is required 检查是否需要认证booleanssl()Returns the value of thesslrecord component.booleanstarttls()Returns the value of thestarttlsrecord component.timeout()Returns the value of thetimeoutrecord component.toString()Return string representation with masked sensitive fields 返回屏蔽敏感字段的字符串表示username()Returns the value of theusernamerecord component.
-
Constructor Details
-
EmailConfig
public EmailConfig(String host, int port, String username, String password, String oauth2Token, boolean ssl, boolean starttls, String defaultFrom, String defaultFromName, Duration timeout, Duration connectionTimeout, int maxRetries, int poolSize, Duration poolIdleTimeout, boolean debug, DkimConfig dkim) Creates an instance of aEmailConfigrecord class.- Parameters:
host- the value for thehostrecord componentport- the value for theportrecord componentusername- the value for theusernamerecord componentpassword- the value for thepasswordrecord componentoauth2Token- the value for theoauth2Tokenrecord componentssl- the value for thesslrecord componentstarttls- the value for thestarttlsrecord componentdefaultFrom- the value for thedefaultFromrecord componentdefaultFromName- the value for thedefaultFromNamerecord componenttimeout- the value for thetimeoutrecord componentconnectionTimeout- the value for theconnectionTimeoutrecord componentmaxRetries- the value for themaxRetriesrecord componentpoolSize- the value for thepoolSizerecord componentpoolIdleTimeout- the value for thepoolIdleTimeoutrecord componentdebug- the value for thedebugrecord componentdkim- the value for thedkimrecord component
-
-
Method Details
-
builder
-
requiresAuth
public boolean requiresAuth()Check if authentication is required 检查是否需要认证- Returns:
- true if authentication is required | 需要认证返回true
-
hasOAuth2
public boolean hasOAuth2()Check if OAuth2 authentication is configured 检查是否配置了OAuth2认证- Returns:
- true if OAuth2 is configured | 配置了OAuth2返回true
-
hasDkim
public boolean hasDkim()Check if DKIM signing is configured 检查是否配置了DKIM签名- Returns:
- true if DKIM is configured | 配置了DKIM返回true
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
host
Returns the value of thehostrecord component.- Returns:
- the value of the
hostrecord component
-
port
public int port()Returns the value of theportrecord component.- Returns:
- the value of the
portrecord component
-
username
Returns the value of theusernamerecord component.- Returns:
- the value of the
usernamerecord component
-
password
Returns the value of thepasswordrecord component.- Returns:
- the value of the
passwordrecord component
-
oauth2Token
Returns the value of theoauth2Tokenrecord component.- Returns:
- the value of the
oauth2Tokenrecord component
-
ssl
public boolean ssl()Returns the value of thesslrecord component.- Returns:
- the value of the
sslrecord component
-
starttls
public boolean starttls()Returns the value of thestarttlsrecord component.- Returns:
- the value of the
starttlsrecord component
-
defaultFrom
Returns the value of thedefaultFromrecord component.- Returns:
- the value of the
defaultFromrecord component
-
defaultFromName
Returns the value of thedefaultFromNamerecord component.- Returns:
- the value of the
defaultFromNamerecord component
-
timeout
Returns the value of thetimeoutrecord component.- Returns:
- the value of the
timeoutrecord component
-
connectionTimeout
Returns the value of theconnectionTimeoutrecord component.- Returns:
- the value of the
connectionTimeoutrecord component
-
maxRetries
public int maxRetries()Returns the value of themaxRetriesrecord component.- Returns:
- the value of the
maxRetriesrecord component
-
poolSize
public int poolSize()Returns the value of thepoolSizerecord component.- Returns:
- the value of the
poolSizerecord component
-
poolIdleTimeout
Returns the value of thepoolIdleTimeoutrecord component.- Returns:
- the value of the
poolIdleTimeoutrecord component
-
debug
public boolean debug()Returns the value of thedebugrecord component.- Returns:
- the value of the
debugrecord component
-
dkim
Returns the value of thedkimrecord component.- Returns:
- the value of the
dkimrecord component
-