From 815f6b82c58e8e50a0cf42ae5d2aa135e8adcc97 Mon Sep 17 00:00:00 2001 From: guqing <38999863+guqing@users.noreply.github.com> Date: Sun, 8 Oct 2023 17:44:14 +0800 Subject: [PATCH] feat: add encryption setting for email notifier (#4686) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind improvement /area core /milestone 2.10.x #### What this PR does / why we need it: 为邮件通知发件设置增加加密方式配置 #### Which issue(s) this PR fixes: Fixes #4674 #### Does this PR introduce a user-facing change? ```release-note 为邮件通知发件设置增加加密方式配置 ``` --- .../run/halo/app/notification/EmailNotifier.java | 15 ++++++++++++++- .../main/resources/extensions/notification.yaml | 12 ++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/run/halo/app/notification/EmailNotifier.java b/application/src/main/java/run/halo/app/notification/EmailNotifier.java index 1a10e1d3c..ee596283c 100644 --- a/application/src/main/java/run/halo/app/notification/EmailNotifier.java +++ b/application/src/main/java/run/halo/app/notification/EmailNotifier.java @@ -107,7 +107,19 @@ public class EmailNotifier implements ReactiveNotifier { Properties props = javaMailSender.getJavaMailProperties(); props.put("mail.transport.protocol", "smtp"); props.put("mail.smtp.auth", "true"); - props.put("mail.smtp.starttls.enable", "true"); + if ("SSL".equals(emailSenderConfig.getEncryption())) { + props.put("mail.smtp.ssl.enable", "true"); + } + + if ("TLS".equals(emailSenderConfig.getEncryption())) { + props.put("mail.smtp.starttls.enable", "true"); + } + + if ("NONE".equals(emailSenderConfig.getEncryption())) { + props.put("mail.smtp.ssl.enable", "false"); + props.put("mail.smtp.starttls.enable", "false"); + } + if (log.isDebugEnabled()) { props.put("mail.debug", "true"); } @@ -154,6 +166,7 @@ public class EmailNotifier implements ReactiveNotifier { private String password; private String host; private Integer port; + private String encryption; /** * Gets email display name. diff --git a/application/src/main/resources/extensions/notification.yaml b/application/src/main/resources/extensions/notification.yaml index 70fb1389c..b50cf5b6d 100644 --- a/application/src/main/resources/extensions/notification.yaml +++ b/application/src/main/resources/extensions/notification.yaml @@ -47,6 +47,18 @@ spec: label: "端口号" name: port validation: required + - $formkit: select + if: "$enable" + label: "加密方式" + name: encryption + value: "SSL" + options: + - label: "SSL" + value: "SSL" + - label: "TLS" + value: "TLS" + - label: "不加密" + value: "NONE" --- apiVersion: notification.halo.run/v1alpha1 kind: ReasonType