Skip to content

基于 jakarta.mail 且无缝集成响应式编程的邮件发送器

License

Notifications You must be signed in to change notification settings

JesseZ332623/Reactive-Email-Sender

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

基于 jakarta.mail 且无缝集成响应式编程的邮件发送器

用法

依赖地址

本依赖已发布至 Maven 中央仓库, 可以访问:Reactive-Email-Sender, 也可以在 pom.xml 中直接配置:

📢 重要通知

1.1.5 版本完成了模块化迁移, 以及更细粒度的参数控制,强烈建议使用新版。

<dependency>
    <groupId>io.github.jessez332623</groupId>
    <artifactId>reactive_email_sender</artifactId>
    <version>1.1.5</version>
</dependency>

属性配置

# 是否启用本依赖?(默认启用)
app.reactive-email-sender.enabled=true

# 提供 SMTP 服务的运营商主机名
app.reactive-email-sender.smtp-host=smtp.qq.com

# SMTP 端口号
app.reactive-email-sender.smtp-port=465

# 最大邮件发送尝试次数(默认 3 回)
app.reactive-email-sender.backoff.max-attempt-times=5

# 指数退避起始时间间隔(单位:秒,默认为 1)
app.reactive-email-sender.backoff.start-backoff-interval=2

# 指数退避封顶时间间隔(单位:秒,默认为 10)
app.reactive-email-sender.backoff.max-backoff-interval=5

# 附件大小的上限(单位:MB,默认为 8)
app.reactive-email-sender.max-attachment-size=8

# 发件人邮箱地址
app.reactive-email-sender.sender-email=[your-email]

# 邮箱服务授权码(不建议直接写配置上)
app.reactive-email-sender.auth-code=[your-auth-code]

# 额外的 Session 属性添加示例
app.reactive-email-sender.session-props.mail.smtp.ssl.enable=true
app.reactive-email-sender.session-props.mail.smtp.auth=true
app.reactive-email-sender.session-props.mail.smtp.connectiontimeout=5000

从配置之外读取邮箱授权码

本依赖声明 EmailServiceAuthCodeGetter 接口:

/**
 * 邮箱服务授权码获取接口,
 * 用户可以实现该接口,从任何地方(如:环境变量、数据库等)获取授权码。
 */
public interface EmailServiceAuthCodeGetter
{
    default String get() { return null; }
}

可以实现该接口,示例如下(从数据库读取授权码):

@Service
public class EmailAuthService implements EmailServiceAuthCodeGetter
{
    @Autowired
    private EmailAuthRepository emailAuthRepository;

    @Value("${app.reactive-email-sender.sender-email}")
    private String senderEmail;

    @Override
    public String get()
    {
        return
        this.emailAuthRepository
            .findAuthCodeByEmail(senderEmail)
            .block();
    }
}

代码速览

测试用例

文档

LICENCE

Apache License Version 2.0

Latest Update

2025.09.26

About

基于 jakarta.mail 且无缝集成响应式编程的邮件发送器

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages