邮件服务设置
This commit is contained in:
parent
c066d99492
commit
7f06194cff
|
@ -63,7 +63,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jetty</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
|
|
@ -28,7 +28,7 @@ public interface ParamConstants {
|
|||
}
|
||||
|
||||
enum Classify implements ParamConstants {
|
||||
|
||||
MAIL("meter"),
|
||||
REGISTRY("registry");
|
||||
|
||||
private String value;
|
||||
|
@ -85,4 +85,29 @@ public interface ParamConstants {
|
|||
this.value = value;
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
private String key;
|
||||
private Integer value;
|
||||
|
||||
private MAIL(String key, Integer value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package io.metersphere.controller;
|
||||
|
||||
import io.metersphere.base.domain.SystemParameter;
|
||||
import io.metersphere.service.SystemParameterService;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/system")
|
||||
public class SystemParameterController {
|
||||
@Resource
|
||||
private SystemParameterService SystemParameterService;
|
||||
@PostMapping("/edit/email")
|
||||
public void editMail(@RequestBody List<SystemParameter> SystemParameter){
|
||||
SystemParameterService.editMail(SystemParameter);
|
||||
}
|
||||
@PostMapping("/testConnection")
|
||||
public void testConnection(@RequestBody HashMap<String, String> hashMap){
|
||||
SystemParameterService.testConnection(hashMap);
|
||||
}
|
||||
|
||||
}
|
|
@ -4,14 +4,22 @@ 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.utils.EncryptUtils;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
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 {
|
||||
|
||||
|
@ -31,4 +39,43 @@ public class SystemParameterService {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
public void editMail(List<SystemParameter> parameters){
|
||||
List<SystemParameter> paramList = this.getParamList(ParamConstants.Classify.MAIL.getValue());
|
||||
boolean empty = paramList.size() < 2;
|
||||
parameters.forEach(parameter -> {
|
||||
if (parameter.getParamKey().equals(ParamConstants.MAIL.PASSWORD.getKey())) {
|
||||
String string = EncryptUtils.aesEncrypt(parameter.getParamValue()).toString();
|
||||
parameter.setParamValue(string);
|
||||
}
|
||||
if (empty) {
|
||||
systemParameterMapper.insert(parameter);
|
||||
} else {
|
||||
systemParameterMapper.updateByPrimaryKey(parameter);
|
||||
}
|
||||
});
|
||||
}
|
||||
public List<SystemParameter> getParamList(String type) {
|
||||
SystemParameterExample example = new SystemParameterExample();
|
||||
example.createCriteria().andParamKeyLike(type + "%");
|
||||
return systemParameterMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public void testConnection(HashMap<String, String> hashMap){
|
||||
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
|
||||
javaMailSender.setDefaultEncoding("UTF-8");
|
||||
javaMailSender.setHost(hashMap.get(ParamConstants.MAIL.PORT.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()));
|
||||
Properties props = new Properties();
|
||||
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");
|
||||
}
|
||||
if (BooleanUtils.toBoolean(hashMap.get(ParamConstants.MAIL.TLS.getKey()))) {
|
||||
props.put("mail.smtp.starttls.enable", "true");
|
||||
}
|
||||
javaMailSender.setJavaMailProperties(props);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import OrganizationMember from "../../settings/organization/OrganizationMember";
|
|||
import Member from "../../settings/workspace/WorkspaceMember";
|
||||
import TestCaseReportTemplate from "../../settings/workspace/TestCaseReportTemplate";
|
||||
import TestResourcePool from "../../settings/system/TestResourcePool";
|
||||
import SystemParameterSetting from "../../settings/system/SystemParameterSetting";
|
||||
import MsProject from "../../project/MsProject";
|
||||
import OrganizationWorkspace from "../../settings/organization/OrganizationWorkspace";
|
||||
import PersonSetting from "../../settings/personal/PersonSetting";
|
||||
|
@ -80,11 +81,16 @@ const router = new VueRouter({
|
|||
path: 'testresourcepool',
|
||||
component: TestResourcePool
|
||||
},
|
||||
{
|
||||
path: 'systemparametersetting',
|
||||
component: SystemParameterSetting
|
||||
},
|
||||
{
|
||||
path: 'testcase/report/template',
|
||||
name: 'testCaseReportTemplate',
|
||||
component: TestCaseReportTemplate
|
||||
}
|
||||
},
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<template>
|
||||
<div>
|
||||
<!--Domain name binding-->
|
||||
<el-row type="flex" justify="start">
|
||||
<el-col :span="8">
|
||||
<h3>{{$t('load_test.domain_bind')}}</h3>
|
||||
|
@ -7,7 +8,7 @@
|
|||
</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<!-- -->
|
||||
<!--Domain name binding form -->
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-table :data="domains" size="mini" class="tb-edit" align="center" border highlight-current-row>
|
||||
|
@ -40,6 +41,7 @@
|
|||
v-model="row.enable"
|
||||
active-color="#13ce66"
|
||||
inactive-color="#ff4949"
|
||||
active-value="readOnly"
|
||||
@click="confirmEdit(row)"
|
||||
>
|
||||
</el-switch>
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<el-menu-item index="/setting/organization">{{$t('commons.organization')}}</el-menu-item>
|
||||
<el-menu-item index="/setting/systemworkspace">{{$t('commons.workspace')}}</el-menu-item>
|
||||
<el-menu-item index="/setting/testresourcepool">{{$t('commons.test_resource_pool')}}</el-menu-item>
|
||||
<el-menu-item index="/setting/systemparametersetting">{{$t('commons.system_parameter_setting')}}</el-menu-item>
|
||||
</el-submenu>
|
||||
|
||||
<el-submenu index="2" v-permission="['org_admin']" v-if="isCurrentOrganizationAdmin">
|
||||
|
|
|
@ -0,0 +1,236 @@
|
|||
<template>
|
||||
<div>
|
||||
<el-card class="box-card" v-loading="result.loading">
|
||||
<template v-slot:header>
|
||||
<h2>{{$t('system_parameter_setting.mailbox_service_settings')}}</h2>
|
||||
</template>
|
||||
<!--邮件表单-->
|
||||
<el-form :inline="true" :model="formInline" :rules="rules" ref="formInline" class="demo-form-inline"
|
||||
:disabled="show" v-loading="loading">
|
||||
<el-row>
|
||||
<el-col>
|
||||
<el-form-item :label="$t('system_parameter_setting.SMTP_host')" prop="host">
|
||||
</el-form-item>
|
||||
<el-input v-model="formInline.host" :placeholder="$t('system_parameter_setting.SMTP_host')"
|
||||
v-on:input="host"></el-input>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col>
|
||||
<el-form-item :label="$t('system_parameter_setting.SMTP_port')" prop="port">
|
||||
</el-form-item>
|
||||
<el-input v-model="formInline.port" :placeholder="$t('system_parameter_setting.SMTP_port')"
|
||||
v-on:input="port"></el-input>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col>
|
||||
<el-form-item :label="$t('system_parameter_setting.SMTP_account')" prop="account">
|
||||
</el-form-item>
|
||||
<el-input v-model="formInline.account" :placeholder="$t('system_parameter_setting.SMTP_account')"
|
||||
v-on:input="account"></el-input>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col>
|
||||
<el-form-item :label="$t('system_parameter_setting.SMTP_password')" prop="password">
|
||||
</el-form-item>
|
||||
<el-input v-model="formInline.password" :placeholder="$t('system_parameter_setting.SMTP_password')"
|
||||
show-password></el-input>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!---->
|
||||
<div style="border: 0px;margin-bottom: 20px;margin-top: 20px">
|
||||
<el-checkbox v-model="SSL" label="开启SSL(如果SMTP端口是465,通常需要启用SSL)"></el-checkbox>
|
||||
</div>
|
||||
<div style="border: 0px;margin-bottom: 20px">
|
||||
<el-checkbox v-model="TLS" label="开启TLS(如果SMTP端口是587,通常需要启用TLS)"></el-checkbox>
|
||||
</div>
|
||||
<div style="border: 0px;margin-bottom: 20px">
|
||||
<el-checkbox v-model="SMTP" label="是否匿名 SMTP"></el-checkbox>
|
||||
</div>
|
||||
<template v-slot:footer>
|
||||
</template>
|
||||
</el-form>
|
||||
<div style="margin-left: 640px">
|
||||
<el-button type="primary" @click="testConnection('formInline')" :disabled="disabledConnection">
|
||||
{{$t('system_parameter_setting.test_connection')}}
|
||||
</el-button>
|
||||
<el-button @click="edit" v-if="showEdit">{{$t('commons.edit')}}</el-button>
|
||||
<el-button type="success" @click="save('formInline')" v-if="showSave" :disabled="disabledSave">
|
||||
{{$t('commons.save')}}
|
||||
</el-button>
|
||||
<el-button @click="cancel" type="info" v-if="showCancel">{{$t('commons.cancel')}}</el-button>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
export default {
|
||||
name: "SystemParameterSetting",
|
||||
data() {
|
||||
return {
|
||||
formInline: {
|
||||
host: 'smtp.163.com',
|
||||
port: '465',
|
||||
account: 'xjj0608@153.com',
|
||||
password: '2345678',
|
||||
},
|
||||
result: {},
|
||||
SSL: false,
|
||||
TLS: false,
|
||||
SMTP: true,
|
||||
showEdit: true,
|
||||
showSave: false,
|
||||
showCancel: false,
|
||||
show: true,
|
||||
disabledConnection: false,
|
||||
disabledSave: false,
|
||||
loading: false,
|
||||
rules: {
|
||||
host: [
|
||||
{
|
||||
required: true,
|
||||
message: this.$t('commons.host_cannot_be_empty')
|
||||
},
|
||||
],
|
||||
port: [
|
||||
{
|
||||
required: true,
|
||||
message: ' '
|
||||
}
|
||||
],
|
||||
account: [
|
||||
{
|
||||
required: true,
|
||||
message: ' '
|
||||
}]
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
host() {
|
||||
|
||||
let host = this.formInline.host;
|
||||
if (!host) {
|
||||
this.disabledConnection = true;
|
||||
this.disabledSave = true;
|
||||
} else {
|
||||
this.disabledConnection = false;
|
||||
this.disabledSave = false;
|
||||
}
|
||||
},
|
||||
port() {
|
||||
|
||||
let port = this.formInline.port;
|
||||
if (!port) {
|
||||
this.disabledConnection = true;
|
||||
this.disabledSave = true;
|
||||
} else {
|
||||
this.disabledConnection = false;
|
||||
this.disabledSave = false;
|
||||
}
|
||||
},
|
||||
account() {
|
||||
let account = this.formInline.account;
|
||||
if (!account) {
|
||||
this.disabledConnection = true;
|
||||
this.disabledSave = true;
|
||||
} else {
|
||||
this.disabledConnection = false;
|
||||
this.disabledSave = false;
|
||||
}
|
||||
},
|
||||
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,
|
||||
};
|
||||
this.$refs[formInline].validate((valid) => {
|
||||
if (valid) {
|
||||
this.result = this.$post("/system/testConnection", param, response => {
|
||||
let flag = response.success;
|
||||
if (flag) {
|
||||
this.$success(this.$t('commons.connection_successful'));
|
||||
} else {
|
||||
this.$message.error(this.$t('commons.connection_failed'));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
},
|
||||
edit() {
|
||||
this.showEdit = false;
|
||||
this.showSave = true;
|
||||
this.showCancel = true;
|
||||
this.show = false;
|
||||
},
|
||||
save(formInline) {
|
||||
this.showEdit = true;
|
||||
this.showCancel = false;
|
||||
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}
|
||||
]
|
||||
|
||||
this.$refs[formInline].validate(valid => {
|
||||
if (valid) {
|
||||
this.result = this.$post("/system/edit/email", param, response => {
|
||||
let flag = response.success;
|
||||
if (flag) {
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
} else {
|
||||
this.$message.error(this.$t('commons.save_failed'));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
},
|
||||
cancel() {
|
||||
this.showEdit = true;
|
||||
this.showCancel = false;
|
||||
this.showSave = false;
|
||||
this.show = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.text {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.item {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.box-card {
|
||||
padding-left: 5px;
|
||||
}
|
||||
|
||||
/deep/ .el-input__inner {
|
||||
border-width: 0px;
|
||||
border-bottom-width: 1px;
|
||||
}
|
||||
</style>
|
|
@ -57,6 +57,14 @@ export default {
|
|||
'exit_system': 'Exit System',
|
||||
'verification': 'Verification',
|
||||
'set_admin': 'Set Admin',
|
||||
'system_parameter_setting': 'System Parameter Setting',
|
||||
'connection_successful': 'Connection successful',
|
||||
'connection_failed': 'Connection failed',
|
||||
'save_failed': 'Saved failed',
|
||||
'host_cannot_be_empty': 'Host cannot be empty',
|
||||
'port_cannot_be_empty': 'Port cannot be empty',
|
||||
'account_cannot_be_empty': 'Account cannot be empty',
|
||||
|
||||
},
|
||||
workspace: {
|
||||
'create': 'Create Workspace',
|
||||
|
@ -422,6 +430,14 @@ export default {
|
|||
'status_change_success': 'Successfully changed the status!',
|
||||
'status_change_failed': 'Failed to change the status, resource pool is invalid!',
|
||||
},
|
||||
system_parameter_setting: {
|
||||
'mailbox_service_settings': 'Mailbox Service Settings',
|
||||
'test_connection': 'Test connection',
|
||||
'SMTP_host': 'SMTP host',
|
||||
'SMTP_port': 'SMTP port',
|
||||
'SMTP_account': 'SMTP account',
|
||||
'SMTP_password': 'SMTP password',
|
||||
},
|
||||
i18n: {
|
||||
'home': 'Home'
|
||||
}
|
||||
|
|
|
@ -57,6 +57,13 @@ export default {
|
|||
'exit_system': '退出系统',
|
||||
'verification': '验证',
|
||||
'set_admin': '设置为管理员',
|
||||
'system_parameter_setting': '系统参数设置',
|
||||
'connection_successful': '连接成功',
|
||||
'connection_failed': '连接失败',
|
||||
'save_failed': '保存失败',
|
||||
'host_cannot_be_empty': '主机不能为空',
|
||||
'port_cannot_be_empty': '端口号不能为空',
|
||||
'account_cannot_be_empty': '帐户不能为空',
|
||||
},
|
||||
workspace: {
|
||||
'create': '创建工作空间',
|
||||
|
@ -422,6 +429,14 @@ export default {
|
|||
'status_change_success': '状态修改成功!',
|
||||
'status_change_failed': '状态修改失败, 校验不通过!',
|
||||
},
|
||||
system_parameter_setting: {
|
||||
'mailbox_service_settings': '邮件服务设置',
|
||||
'test_connection': '测试连接',
|
||||
'SMTP_host': 'SMTP主机',
|
||||
'SMTP_port': 'SMTP端口',
|
||||
'SMTP_account': 'SMTP账户',
|
||||
'SMTP_password': 'SMTP密码',
|
||||
},
|
||||
i18n: {
|
||||
'home': '首页'
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue