This commit is contained in:
wenyann 2020-05-25 17:31:45 +08:00
parent 21d7beb82f
commit bc3e3d6fcd
4 changed files with 25 additions and 16 deletions

View File

@ -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;

View File

@ -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<String, String> 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"));
}
}
}

View File

@ -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
test_case_report_template_repeat=The workspace has the same name template
connection_failed=Connection failed

View File

@ -88,3 +88,4 @@ module_created_automatically=若无该模块将自动创建
options=选项
please_input_workspace_member=请填写该工作空间相关人员
test_case_report_template_repeat=同一工作空间下不能存在同名模版
connection_failed=连接失败