From a1aced743557d18dd8e126327f96a3b10d7de7a5 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 24 Nov 2020 17:53:03 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=E5=88=A0=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/track/issue/ZentaoUtils.java | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 backend/src/main/java/io/metersphere/track/issue/ZentaoUtils.java diff --git a/backend/src/main/java/io/metersphere/track/issue/ZentaoUtils.java b/backend/src/main/java/io/metersphere/track/issue/ZentaoUtils.java deleted file mode 100644 index fa34a39224..0000000000 --- a/backend/src/main/java/io/metersphere/track/issue/ZentaoUtils.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.metersphere.track.issue; - -import io.metersphere.commons.utils.EncryptUtils; - -public class ZentaoUtils { - - /** - * @param code Zentao 应用代号 - * @param key Zentao 密钥 - * @return token - */ - public static String getToken(String code, String key, String time) { - return (String) EncryptUtils.md5Encrypt(code + key + time); - } - - /** - * @param url Zentao url - * @param code Zentao 应用代号 - * @param key Zentao 密钥 - * @return url - */ - public static String getUrl(String url, String code, String key) { - String time = String.valueOf(System.currentTimeMillis());; - return url + "api.php?" + "code=" + code + "&time=" + time + "&token=" + getToken(code, key, time); - } -} From a9ff93841b1ecfdd791f0b5444faa052ba4c4b13 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Tue, 24 Nov 2020 18:04:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DMailService?= =?UTF-8?q?=E4=B8=8D=E6=94=AF=E6=8C=81=E9=9D=9ESSL=E7=9A=84SMTP=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=E6=9C=8D=E5=8A=A1=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #768 --- .../notice/service/MailService.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/io/metersphere/notice/service/MailService.java b/backend/src/main/java/io/metersphere/notice/service/MailService.java index 0cc1c5e44e..e5e0261284 100644 --- a/backend/src/main/java/io/metersphere/notice/service/MailService.java +++ b/backend/src/main/java/io/metersphere/notice/service/MailService.java @@ -22,6 +22,7 @@ import io.metersphere.track.request.testreview.SaveTestCaseReviewRequest; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.RegExUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.mail.MailException; @@ -340,13 +341,13 @@ public class MailService { } - - private JavaMailSenderImpl getMailSender() { + Properties props = new Properties(); JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); List paramList = systemParameterService.getParamList(ParamConstants.Classify.MAIL.getValue()); javaMailSender.setDefaultEncoding("UTF-8"); - javaMailSender.setProtocol("smtps"); + javaMailSender.setProtocol("smtp"); + for (SystemParameter p : paramList) { switch (p.getParamKey()) { case "smtp.host": @@ -361,14 +362,24 @@ public class MailService { case "smtp.password": javaMailSender.setPassword(EncryptUtils.aesDecrypt(p.getParamValue()).toString()); break; + case "smtp.ssl": + javaMailSender.setProtocol("smtps"); + if (BooleanUtils.toBoolean(p.getParamValue())) { + props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); + } + break; + case "smtp.tls": + String result = BooleanUtils.toString(BooleanUtils.toBoolean(p.getParamValue()), "true", "false"); + props.put("mail.smtp.starttls.enable", result); + props.put("mail.smtp.starttls.required", result); + break; default: break; } } - Properties props = new Properties(); + props.put("mail.smtp.auth", "true"); - props.put("mail.smtp.starttls.enable", "true"); - props.put("mail.smtp.starttls.required", "true"); + props.put("mail.smtp.timeout", "30000"); props.put("mail.smtp.connectiontimeout", "5000"); javaMailSender.setJavaMailProperties(props);