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 430b703312..c775fc7889 100644 --- a/backend/src/main/java/io/metersphere/commons/constants/ParamConstants.java +++ b/backend/src/main/java/io/metersphere/commons/constants/ParamConstants.java @@ -95,8 +95,7 @@ public interface ParamConstants { PASSWORD("smtp.password", 4), SSL("smtp.ssl", 5), TLS("smtp.tls", 6), - SMTP("smtp.smtp", 7); - /* ANON("smtp.anon", 7);*/ + ANON("smtp.anon", 7); private String key; private Integer value; 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 e5e0261284..22321658ce 100644 --- a/backend/src/main/java/io/metersphere/notice/service/MailService.java +++ b/backend/src/main/java/io/metersphere/notice/service/MailService.java @@ -347,6 +347,7 @@ public class MailService { List paramList = systemParameterService.getParamList(ParamConstants.Classify.MAIL.getValue()); javaMailSender.setDefaultEncoding("UTF-8"); javaMailSender.setProtocol("smtp"); + props.put("mail.smtp.auth", "true"); for (SystemParameter p : paramList) { switch (p.getParamKey()) { @@ -373,13 +374,19 @@ public class MailService { props.put("mail.smtp.starttls.enable", result); props.put("mail.smtp.starttls.required", result); break; + case "smtp.anon": + boolean isAnon = BooleanUtils.toBoolean(p.getParamValue()); + if (isAnon) { + props.put("mail.smtp.auth", "false"); + javaMailSender.setUsername(null); + javaMailSender.setPassword(null); + } + break; default: break; } } - props.put("mail.smtp.auth", "true"); - props.put("mail.smtp.timeout", "30000"); props.put("mail.smtp.connectiontimeout", "5000"); javaMailSender.setJavaMailProperties(props); diff --git a/backend/src/main/java/io/metersphere/service/SystemParameterService.java b/backend/src/main/java/io/metersphere/service/SystemParameterService.java index 680a0886e0..255d6159ce 100644 --- a/backend/src/main/java/io/metersphere/service/SystemParameterService.java +++ b/backend/src/main/java/io/metersphere/service/SystemParameterService.java @@ -86,7 +86,14 @@ public class SystemParameterService { javaMailSender.setUsername(hashMap.get(ParamConstants.MAIL.ACCOUNT.getKey())); javaMailSender.setPassword(hashMap.get(ParamConstants.MAIL.PASSWORD.getKey())); Properties props = new Properties(); - props.put("mail.smtp.auth", "true"); + boolean isAnon = Boolean.parseBoolean(hashMap.get(ParamConstants.MAIL.ANON.getKey())); + if (isAnon) { + props.put("mail.smtp.auth", "false"); + javaMailSender.setUsername(null); + javaMailSender.setPassword(null); + } else { + props.put("mail.smtp.auth", "true"); + } if (BooleanUtils.toBoolean(hashMap.get(ParamConstants.MAIL.SSL.getKey()))) { props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); } diff --git a/frontend/src/business/components/settings/system/EmailSetting.vue b/frontend/src/business/components/settings/system/EmailSetting.vue index 47d845993f..8de498081d 100644 --- a/frontend/src/business/components/settings/system/EmailSetting.vue +++ b/frontend/src/business/components/settings/system/EmailSetting.vue @@ -45,7 +45,7 @@
- +
@@ -120,7 +120,7 @@ export default { this.$set(this.formInline, "password", response.data[3].paramValue); this.$set(this.formInline, "SSL", JSON.parse(response.data[4].paramValue)); this.$set(this.formInline, "TLS", JSON.parse(response.data[5].paramValue)); - this.$set(this.formInline, "SMTP", JSON.parse(response.data[6].paramValue)); + this.$set(this.formInline, "ANON", JSON.parse(response.data[6].paramValue)); this.$nextTick(() => { this.$refs.formInline.clearValidate(); }) @@ -143,7 +143,7 @@ export default { "smtp.password": this.formInline.password, "smtp.ssl": this.formInline.SSL, "smtp.tls": this.formInline.TLS, - "smtp.smtp": this.formInline.SMTP, + "smtp.anon": this.formInline.ANON, }; this.$refs[formInline].validate((valid) => { if (valid) { @@ -173,7 +173,7 @@ export default { {paramKey: "smtp.password", paramValue: this.formInline.password, type: "password", sort: 4}, {paramKey: "smtp.ssl", paramValue: this.formInline.SSL, type: "text", sort: 5}, {paramKey: "smtp.tls", paramValue: this.formInline.TLS, type: "text", sort: 6}, - {paramKey: "smtp.smtp", paramValue: this.formInline.SMTP, type: "text", sort: 7} + {paramKey: "smtp.anon", paramValue: this.formInline.ANON, type: "text", sort: 7} ] this.$refs[formInline].validate(valid => { diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index d237a3a018..7bffa63843 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -1005,7 +1005,7 @@ export default { SMTP_password: 'SMTP密码', SSL: '开启SSL(如果SMTP端口是465,通常需要启用SSL)', TLS: '开启TLS(如果SMTP端口是587,通常需要启用TLS)', - SMTP: '是否匿名 SMTP', + SMTP: '是否免密 SMTP', host: '主机号不能为空', port: '端口号不能为空', account: '账户不能为空', diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index 7b78e3a37b..989eecbb43 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -1006,7 +1006,7 @@ export default { SMTP_password: 'SMTP密碼', SSL: '開啟SSL(如果SMTP端口是465,通常需要啟用SSL)', TLS: '開啟TLS(如果SMTP端口是587,通常需要啟用TLS)', - SMTP: '是否匿名 SMTP', + SMTP: '是否免密 SMTP', host: '主機號不能為空', port: '端口號不能為空', account: '賬戶不能為空',