From bc3e3d6fcd7165f2c6f377d21e22ad6cdaa2cdbd Mon Sep 17 00:00:00 2001 From: wenyann <64353056+wenyann@users.noreply.github.com> Date: Mon, 25 May 2020 17:31:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/constants/ParamConstants.java | 19 ++++++++++--------- .../service/SystemParameterService.java | 18 ++++++++++++------ .../resources/i18n/messages_en_US.properties | 3 ++- .../resources/i18n/messages_zh_CN.properties | 1 + 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/backend/src/main/java/io/metersphere/commons/constants/ParamConstants.java b/backend/src/main/java/io/metersphere/commons/constants/ParamConstants.java index e2fe313ed2..482192246c 100644 --- a/backend/src/main/java/io/metersphere/commons/constants/ParamConstants.java +++ b/backend/src/main/java/io/metersphere/commons/constants/ParamConstants.java @@ -28,7 +28,7 @@ public interface ParamConstants { } enum Classify implements ParamConstants { - MAIL("meter"), + MAIL("smtp"), REGISTRY("registry"); private String value; @@ -86,14 +86,15 @@ public interface ParamConstants { } } - public static enum MAIL { - HOST("meter.host", 1), - PORT("meter.port", 2), - ACCOUNT("meter.account", 3), - PASSWORD("meter.password", 4), - SSL("meter.ssl", 5), - TLS("meter.tls", 6), - ANON("meter.anon", 7); + enum MAIL { + SERVER("smtp.server", 1), + PORT("smtp.port", 2), + ACCOUNT("smtp.account", 3), + PASSWORD("smtp.password", 4), + SSL("smtp.ssl", 5), + TLS("smtp.tls", 6), + SMTP("smtp.smtp", 7); + /* ANON("smtp.anon", 7);*/ private String key; private Integer value; diff --git a/backend/src/main/java/io/metersphere/service/SystemParameterService.java b/backend/src/main/java/io/metersphere/service/SystemParameterService.java index e6d4635a40..725afb6768 100644 --- a/backend/src/main/java/io/metersphere/service/SystemParameterService.java +++ b/backend/src/main/java/io/metersphere/service/SystemParameterService.java @@ -4,21 +4,21 @@ import io.metersphere.base.domain.SystemParameter; import io.metersphere.base.domain.SystemParameterExample; import io.metersphere.base.mapper.SystemParameterMapper; import io.metersphere.commons.constants.ParamConstants; +import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.EncryptUtils; +import io.metersphere.i18n.Translator; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import javax.mail.MessagingException; import java.util.HashMap; import java.util.List; import java.util.Properties; -import org.springframework.mail.javamail.JavaMailSenderImpl; - - -import javax.annotation.Resource; - @Service public class SystemParameterService { @@ -65,7 +65,7 @@ public class SystemParameterService { public void testConnection(HashMap hashMap) { JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); javaMailSender.setDefaultEncoding("UTF-8"); - javaMailSender.setHost(hashMap.get(ParamConstants.MAIL.PORT.getKey())); + javaMailSender.setHost(hashMap.get(ParamConstants.MAIL.SERVER.getKey())); javaMailSender.setPort(Integer.valueOf(hashMap.get(ParamConstants.MAIL.PORT.getKey()))); javaMailSender.setUsername(hashMap.get(ParamConstants.MAIL.ACCOUNT.getKey())); javaMailSender.setPassword(hashMap.get(ParamConstants.MAIL.PASSWORD.getKey())); @@ -78,6 +78,12 @@ public class SystemParameterService { props.put("mail.smtp.starttls.enable", "true"); } javaMailSender.setJavaMailProperties(props); + try { + javaMailSender.testConnection(); + } catch (MessagingException e) { + MSException.throwException(Translator.get("connection_failed")); + } + } } diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index 74b599f304..2d86e69f98 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -87,4 +87,5 @@ do_not_modify_header_order=Do not modify the header order module_created_automatically=If there is no such module, will be created automatically options=options please_input_workspace_member=Please input workspace merber -test_case_report_template_repeat=The workspace has the same name template \ No newline at end of file +test_case_report_template_repeat=The workspace has the same name template +connection_failed=Connection failed \ No newline at end of file diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 06d7054d3b..38e277f08d 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -88,3 +88,4 @@ module_created_automatically=若无该模块将自动创建 options=选项 please_input_workspace_member=请填写该工作空间相关人员 test_case_report_template_repeat=同一工作空间下不能存在同名模版 +connection_failed=连接失败 From 98f955a74e51090fb67b41dffcd1be5280ef8c94 Mon Sep 17 00:00:00 2001 From: wenyann <64353056+wenyann@users.noreply.github.com> Date: Mon, 25 May 2020 17:33:34 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/SystemParameterSetting.vue | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/frontend/src/business/components/settings/system/SystemParameterSetting.vue b/frontend/src/business/components/settings/system/SystemParameterSetting.vue index 4995ebf9b3..066869440c 100644 --- a/frontend/src/business/components/settings/system/SystemParameterSetting.vue +++ b/frontend/src/business/components/settings/system/SystemParameterSetting.vue @@ -125,13 +125,13 @@ }, testConnection(formInline) { let param = { - "meter.host": this.formInline.host, - "meter.port": this.formInline.port, - "meter.account": this.formInline.account, - "meter.password": this.formInline.password, - "meter.ssl": this.SSL, - "meter.tls": this.TLS, - "meter.smtp": this.SMTP, + "smtp.server": this.formInline.host, + "smtp.port": this.formInline.port, + "smtp.account": this.formInline.account, + "smtp.password": this.formInline.password, + "smtp.ssl": this.SSL, + "smtp.tls": this.TLS, + "smtp.smtp": this.SMTP, }; this.$refs[formInline].validate((valid) => { if (valid) { @@ -140,8 +140,10 @@ if (flag) { this.$success(this.$t('commons.connection_successful')); } else { - this.$message.error(this.$t('commons.connection_failed')); + this.$error(this.$t('commons.connection_failed')); } + }).catch(() => { + this.$info(this.$t('commons.connection_failed')); }); } else { return false; @@ -160,13 +162,13 @@ this.showSave = false; this.show = true; let param = [ - {paramKey: "meter.host", paramValue: this.formInline.host, type: "text", sort: 1}, - {paramKey: "meter.port", paramValue: this.formInline.port, type: "text", sort: 2}, - {paramKey: "meter.account", paramValue: this.formInline.account, type: "text", sort: 3}, - {paramKey: "meter.password", paramValue: this.formInline.password, type: "password", sort: 4}, - {paramKey: "meter.ssl", paramValue: this.SSL, type: "text", sort: 5}, - {paramKey: "meter.tls", paramValue: this.TLS, type: "text", sort: 6}, - {paramKey: "meter.smtp", paramValue: this.SMTP, type: "text", sort: 7} + {paramKey: "smtp.host", paramValue: this.formInline.host, type: "text", sort: 1}, + {paramKey: "smtp.port", paramValue: this.formInline.port, type: "text", sort: 2}, + {paramKey: "smtp.account", paramValue: this.formInline.account, type: "text", sort: 3}, + {paramKey: "smtp.password", paramValue: this.formInline.password, type: "password", sort: 4}, + {paramKey: "smtp.ssl", paramValue: this.SSL, type: "text", sort: 5}, + {paramKey: "smtp.tls", paramValue: this.TLS, type: "text", sort: 6}, + {paramKey: "smtp.smtp", paramValue: this.SMTP, type: "text", sort: 7} ] this.$refs[formInline].validate(valid => {