diff --git a/bubble-spring-boot-starters/bubble-spring-boot-starter-mail/src/main/java/cn/fxbin/bubble/mail/MailProperties.java b/bubble-spring-boot-starters/bubble-spring-boot-starter-mail/src/main/java/cn/fxbin/bubble/mail/MailProperties.java index 984004e2..a7bd3659 100644 --- a/bubble-spring-boot-starters/bubble-spring-boot-starter-mail/src/main/java/cn/fxbin/bubble/mail/MailProperties.java +++ b/bubble-spring-boot-starters/bubble-spring-boot-starter-mail/src/main/java/cn/fxbin/bubble/mail/MailProperties.java @@ -1,10 +1,12 @@ package cn.fxbin.bubble.mail; +import com.google.common.collect.Lists; 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.List; import java.util.Map; import static cn.fxbin.bubble.mail.MailProperties.BUBBLE_MAIL_PREFIX; @@ -63,6 +65,16 @@ public class MailProperties { * */ private String isAuth = "true"; + /** + * 重试间隔(单位:秒),默认为5秒 + */ + private int retryInterval = 5; + + /** + * 重试次数,默认为1次 + */ + private int maxRetries = 1; + /** * 多租户配置时需要配置此项,指定默认主租户 */ @@ -73,4 +85,9 @@ public class MailProperties { */ private Map tenant = Maps.newHashMap(); + /** + * 黑名单 + */ + private List blacklist = Lists.newArrayList(); + } \ No newline at end of file diff --git a/bubble-spring-boot-starters/bubble-spring-boot-starter-mail/src/main/java/cn/fxbin/bubble/mail/autoconfigure/MailAutoConfiguration.java b/bubble-spring-boot-starters/bubble-spring-boot-starter-mail/src/main/java/cn/fxbin/bubble/mail/autoconfigure/MailAutoConfiguration.java index 64b46a00..fee9d025 100644 --- a/bubble-spring-boot-starters/bubble-spring-boot-starter-mail/src/main/java/cn/fxbin/bubble/mail/autoconfigure/MailAutoConfiguration.java +++ b/bubble-spring-boot-starters/bubble-spring-boot-starter-mail/src/main/java/cn/fxbin/bubble/mail/autoconfigure/MailAutoConfiguration.java @@ -3,6 +3,7 @@ import cn.fxbin.bubble.core.util.CollectionUtils; import cn.fxbin.bubble.mail.MailProperties; import jakarta.annotation.Resource; +import org.dromara.email.api.Blacklist; import org.dromara.email.api.MailClient; import org.dromara.email.comm.config.MailSmtpConfig; import org.dromara.email.core.factory.MailFactory; @@ -14,6 +15,7 @@ import org.springframework.context.annotation.Lazy; import org.springframework.util.Assert; +import java.util.List; import java.util.Map; /** @@ -44,9 +46,11 @@ public MailClient mailClient() { .fromAddress(properties.getFromAddress()) .isSSL(properties.getIsSsl()) .isAuth(properties.getIsAuth()) + .maxRetries(properties.getMaxRetries()) + .retryInterval(properties.getRetryInterval()) .build(); MailFactory.put("default", mailSmtpConfig); - return MailFactory.createMailClient("default"); + return MailFactory.createMailClient("default", () -> properties.getBlacklist()); } /** diff --git a/bubble-spring-boot-starters/bubble-spring-boot-starter-mail/src/main/java/org/dromara/email/comm/utils/HtmlUtil.java b/bubble-spring-boot-starters/bubble-spring-boot-starter-mail/src/main/java/org/dromara/email/comm/utils/HtmlUtil.java deleted file mode 100644 index ac63bcf9..00000000 --- a/bubble-spring-boot-starters/bubble-spring-boot-starter-mail/src/main/java/org/dromara/email/comm/utils/HtmlUtil.java +++ /dev/null @@ -1,125 +0,0 @@ -package org.dromara.email.comm.utils; - -import org.dromara.email.comm.errors.MailException; - -import java.io.*; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * HtmlUtil - *

Html相关工具 - * - * @author :Wind - * 2023/6/7 20:15 - **/ -public final class HtmlUtil { - - private static final HtmlUtil htmlUtil = new HtmlUtil(); - - private HtmlUtil() { - } - - /** - * readHtml - *

从resource读取模板文件 - * - * @param name 模板文件名 - * @author :Wind - */ - public static List readHtml(String name) throws MailException { - try (InputStream is = HtmlUtil.class.getResourceAsStream("/template/" + name);) { - return readHtml(is); - } catch (IOException e) { - throw new MailException(e); - } - } - - /** - * readHtml - *

从自定义路径读取模板文件 - * - * @param file 自定义路径file - * @author :Wind - */ - public static List readHtml(File file) throws MailException { - try (InputStream ip = Files.newInputStream(file.toPath());) { - return readHtml(ip); - } catch (IOException e) { - throw new MailException(e); - } - - } - - /** - * readHtml - *

从输入流读取模板文件 - * - * @param inputStream 输入流 - * @author :Wind - */ - public static List readHtml(InputStream inputStream) throws MailException { - List data = new ArrayList<>(); - if (Objects.isNull(inputStream)) { - throw new MailException("The template could not be found!"); - } - try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) { - String line; - while ((line = br.readLine()) != null) { - data.add(line); - } - } catch (IOException e) { - throw new MailException(e); - } - return data; - } - - /** - * replacePlaceholder - *

将所包含占位符的字符串替换为固定值 - * - * @param data 源数据 - * @param parameter key为占位符名称 value为占位符应替换的值 - * @author :Wind - */ - public static List replacePlaceholder(List data, Map parameter) { - for (int i = 0; i < data.size(); i++) { - for (Map.Entry s : parameter.entrySet()) { - String piece = piece(s.getKey()); - if (data.get(i).contains(piece)){ - data.set(i, data.get(i).replace(piece, s.getValue())); - } - } - } - return data; - } - - /** - * pieceHtml - *

将数据拼合为html - * - * @param data 需要拼合的数据 - * @author :Wind - */ - public static String pieceHtml(List data) { - StringBuilder sb = new StringBuilder(); - for (String datum : data) { - sb.append(datum); - sb.append("\r\n"); - } - return sb.toString(); - } - - /** - * piece - *

将参数拼合为完整占位符 - * - * @author :Wind - */ - public static String piece(String parameter) { - return "#{" + parameter + "}"; - } -} diff --git a/bubble-spring-boot-starters/bubble-spring-boot-starter-mail/src/main/java/org/dromara/email/comm/utils/package-info.java b/bubble-spring-boot-starters/bubble-spring-boot-starter-mail/src/main/java/org/dromara/email/comm/utils/package-info.java deleted file mode 100644 index 5ea60717..00000000 --- a/bubble-spring-boot-starters/bubble-spring-boot-starter-mail/src/main/java/org/dromara/email/comm/utils/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * 这是一个bug fix: https://gitee.com/dromara/sms4j/pulls/92 - */ -package org.dromara.email.comm.utils; \ No newline at end of file