-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
bubble-spring-boot-starters/bubble-spring-boot-starter-mail/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>cn.fxbin.bubble</groupId> | ||
<artifactId>bubble-spring-boot-starters</artifactId> | ||
<version>2.0.0.BUILD-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>bubble-spring-boot-starter-mail</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>cn.fxbin.bubble</groupId> | ||
<artifactId>bubble-spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.dromara.sms4j</groupId> | ||
<artifactId>sms4j-Email-core</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
76 changes: 76 additions & 0 deletions
76
...rs/bubble-spring-boot-starter-mail/src/main/java/cn/fxbin/bubble/mail/MailProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package cn.fxbin.bubble.mail; | ||
|
||
import com.google.common.collect.Maps; | ||
import lombok.Data; | ||
import org.dromara.email.comm.config.MailSmtpConfig; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
import java.util.Map; | ||
|
||
import static cn.fxbin.bubble.mail.MailProperties.BUBBLE_MAIL_PREFIX; | ||
|
||
/** | ||
* MailProperties | ||
* | ||
* @author fxbin | ||
* @version v1.0 | ||
* @since 2023/9/7 19:33 | ||
*/ | ||
@Data | ||
@ConfigurationProperties(prefix = BUBBLE_MAIL_PREFIX) | ||
public class MailProperties { | ||
|
||
public static final String BUBBLE_MAIL_PREFIX = "bubble.mail"; | ||
|
||
|
||
/** | ||
* 是否开启 mail,默认:true | ||
*/ | ||
private boolean enabled = true; | ||
|
||
/** | ||
* 端口号 | ||
* */ | ||
private String port; | ||
|
||
/** | ||
* 发件人地址 | ||
* */ | ||
private String fromAddress; | ||
|
||
/** | ||
* 服务器地址 | ||
* */ | ||
private String smtpServer; | ||
|
||
/** | ||
* 账号 | ||
* */ | ||
private String username; | ||
|
||
/** | ||
* 密码 | ||
* */ | ||
private String password; | ||
|
||
/** | ||
* 是否开启ssl 默认开启 | ||
* */ | ||
private String isSsl = "true"; | ||
|
||
/** | ||
* 是否开启验证 默认开启 | ||
* */ | ||
private String isAuth = "true"; | ||
|
||
/** | ||
* 多租户配置时需要配置此项,指定默认主租户 | ||
*/ | ||
private String primary; | ||
|
||
/** | ||
* 多租户配置 | ||
*/ | ||
private Map<String, MailSmtpConfig> tenant = Maps.newHashMap(); | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
...-starter-mail/src/main/java/cn/fxbin/bubble/mail/autoconfigure/MailAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package cn.fxbin.bubble.mail.autoconfigure; | ||
|
||
import cn.fxbin.bubble.core.util.CollectionUtils; | ||
import cn.fxbin.bubble.mail.MailProperties; | ||
import jakarta.annotation.Resource; | ||
import org.dromara.email.api.MailClient; | ||
import org.dromara.email.comm.config.MailSmtpConfig; | ||
import org.dromara.email.core.factory.MailFactory; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Lazy; | ||
import org.springframework.util.Assert; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* MailAutoConfiguration | ||
* | ||
* @author fxbin | ||
* @version v1.0 | ||
* @since 2023/9/7 19:38 | ||
*/ | ||
@Configuration( | ||
proxyBeanMethods = false | ||
) | ||
@ConditionalOnProperty(prefix = MailProperties.BUBBLE_MAIL_PREFIX, name = "enabled", havingValue = "true") | ||
@EnableConfigurationProperties(MailProperties.class) | ||
public class MailAutoConfiguration implements InitializingBean { | ||
|
||
@Resource | ||
private MailProperties properties; | ||
|
||
@Bean | ||
@Lazy | ||
public MailClient mailClient() { | ||
MailSmtpConfig mailSmtpConfig = MailSmtpConfig.builder() | ||
.port(properties.getPort()) | ||
.smtpServer(properties.getSmtpServer()) | ||
.username(properties.getUsername()) | ||
.password(properties.getPassword()) | ||
.fromAddress(properties.getFromAddress()) | ||
.isSSL(properties.getIsSsl()) | ||
.isAuth(properties.getIsAuth()) | ||
.build(); | ||
MailFactory.put("default", mailSmtpConfig); | ||
return MailFactory.createMailClient("default"); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
@Override | ||
public void afterPropertiesSet() throws Exception { | ||
// 多租户配置 | ||
if (properties.isEnabled() && CollectionUtils.isNotEmpty(properties.getTenant())) { | ||
|
||
|
||
Assert.isNull(properties.getPrimary(), "bubble.mail.primary 属性不允许为空"); | ||
Assert.isTrue(properties.getTenant().containsKey(properties.getPrimary()), | ||
"bubble.mail.tenant 属性配置未包含 bubble.mail.primary 指定value"); | ||
|
||
Map<String, MailSmtpConfig> tenantConfig = properties.getTenant(); | ||
tenantConfig.forEach(MailFactory::put); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters