From a8d5405decdfa9a242ee7860a1a1a7be9b6b8e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BF=9E=E5=AE=9D=E5=B1=B1?= <1253070437@qq.com> Date: Tue, 12 Nov 2024 03:39:25 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8D=87=E7=BA=A7=E3=80=91=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=E5=8A=9F=E8=83=BD=E5=8A=A0=E5=85=A5=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=9B=B4=E9=80=9A=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/config/emailConfig/localEmailForm.vue | 33 +++++++++++++++++-- .../modular/email/util/DevEmailLocalUtil.java | 33 +++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/snowy-admin-web/src/views/dev/config/emailConfig/localEmailForm.vue b/snowy-admin-web/src/views/dev/config/emailConfig/localEmailForm.vue index 896842ba..e1079553 100644 --- a/snowy-admin-web/src/views/dev/config/emailConfig/localEmailForm.vue +++ b/snowy-admin-web/src/views/dev/config/emailConfig/localEmailForm.vue @@ -14,6 +14,28 @@ + + + + + + + + + + + + + + + 保存 重置 @@ -41,13 +63,20 @@ loadSpinning.value = false if (data) { data.forEach((item) => { - formData.value[item.configKey] = item.configValue + formData.value[item.configKey] = transferBooleanInValue(item.configValue) }) } else { message.warning('表单项不存在,请初始化数据库') } }) - + // 转换值 + const transferBooleanInValue = (value) => { + if (value === 'true' || value === 'false') { + return value === 'true' + } else { + return value + } + } // 默认要校验的 const formRules = { SNOWY_EMAIL_LOCAL_FROM: [required('请输入发送邮箱号')], diff --git a/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/email/util/DevEmailLocalUtil.java b/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/email/util/DevEmailLocalUtil.java index 89f6bad5..897f07aa 100644 --- a/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/email/util/DevEmailLocalUtil.java +++ b/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/email/util/DevEmailLocalUtil.java @@ -25,6 +25,7 @@ import java.io.File; import java.io.InputStream; import java.util.List; import java.util.Map; +import java.util.Objects; /** * 本地邮件工具类 @@ -40,6 +41,16 @@ public class DevEmailLocalUtil { private static final String SNOWY_EMAIL_LOCAL_FROM_KEY = "SNOWY_EMAIL_LOCAL_FROM"; private static final String SNOWY_EMAIL_LOCAL_PASSWORD_KEY = "SNOWY_EMAIL_LOCAL_PASSWORD"; + private static final String SNOWY_EMAIL_LOCAL_SMTP_HOST_KEY = "SNOWY_EMAIL_LOCAL_SMTP_HOST"; + + private static final String SNOWY_EMAIL_LOCAL_SMTP_PORT_KEY = "SNOWY_EMAIL_LOCAL_SMTP_PORT"; + + private static final String SNOWY_EMAIL_LOCAL_AUTH_KEY = "SNOWY_EMAIL_LOCAL_AUTH"; + + private static final String SNOWY_EMAIL_LOCAL_SSL_ENABLE_KEY = "SNOWY_EMAIL_LOCAL_SSL_ENABLE"; + + private static final String SNOWY_EMAIL_LOCAL_STARTTLS_ENABLE_KEY = "SNOWY_EMAIL_LOCAL_STARTTLS_ENABLE"; + /** * 初始化操作的客户端 * @@ -67,6 +78,28 @@ public class DevEmailLocalUtil { mailAccount = new MailAccount(); mailAccount.setFrom(from); mailAccount.setPass(pass); + + /* SMTP服务器域名 */ + String host = devConfigApi.getValueByKey(SNOWY_EMAIL_LOCAL_SMTP_HOST_KEY); + if (ObjectUtil.isNotEmpty(host)) { + mailAccount.setHost(host); + } + /* SMTP服务端口 */ + String port = devConfigApi.getValueByKey(SNOWY_EMAIL_LOCAL_SMTP_PORT_KEY); + if (ObjectUtil.isNotEmpty(port)) { + mailAccount.setPort(Integer.parseInt(port)); + } + /* 是否需要用户名密码验证 */ + String auth = devConfigApi.getValueByKey(SNOWY_EMAIL_LOCAL_AUTH_KEY); + mailAccount.setAuth(Objects.equals(auth, "true")); + + /* 是否使用SSL安全连接 */ + String sslEnable = devConfigApi.getValueByKey(SNOWY_EMAIL_LOCAL_SSL_ENABLE_KEY); + mailAccount.setSslEnable(Objects.equals(sslEnable, "true")); + + /* 是否使用STARTTLS安全连接 */ + String starttlsEnable = devConfigApi.getValueByKey(SNOWY_EMAIL_LOCAL_STARTTLS_ENABLE_KEY); + mailAccount.setStarttlsEnable(Objects.equals(starttlsEnable, "true")); } public static MailAccount getClient() {