This commit is contained in:
clay 2020-12-19 21:36:11 +08:00
parent c80e84c1c7
commit 51fe11a3a8
4 changed files with 43 additions and 25 deletions

View File

@ -34,7 +34,44 @@ public class MailConfigController {
private Result testSendMail(HttpServletRequest request) {
try {
Account account = (Account) request.getSession().getAttribute("account");
ServerResult serverResult = mailConfigService.testSendMessage(account);
if (account==null){
return new Result(false,0,"系统错误");
}
String sender = HttpServletRequestUtil.getString(request, "sender");
String personal = HttpServletRequestUtil.getString(request, "personal");
String emailSmtpHost = HttpServletRequestUtil.getString(request, "emailSmtpHost");
String emailSmtpPort = HttpServletRequestUtil.getString(request, "emailSmtpPort");
String username = HttpServletRequestUtil.getString(request, "username");
String password = HttpServletRequestUtil.getString(request, "password");
String encryption = HttpServletRequestUtil.getString(request, "encryption");
Integer state = HttpServletRequestUtil.getInteger(request, "state");
String testMail = HttpServletRequestUtil.getString(request, "testMail");
if (sender==null){
return new Result(false,0,"发件人地址不能为空!");
}
if (personal==null){
return new Result(false,0,"发件人信息不能为空!");
}
if (emailSmtpHost ==null){
return new Result(false,0,"服务器地址不能为空!");
}
if (emailSmtpPort ==null){
return new Result(false,0,"服务器端口不能为空!");
}
if (username ==null){
return new Result(false,0,"用户名不能为空!");
}
if (password ==null){
return new Result(false,0,"密码不能为空!");
}
if (encryption ==null){
return new Result(false,0,"加密方式不能为空!");
}
if (testMail ==null){
return new Result(false,0,"测试邮件不能为空!");
}
MailConfig mailConfig = new MailConfig(sender,personal,emailSmtpHost,emailSmtpPort,username,password,encryption,state,testMail);
ServerResult serverResult = mailConfigService.testSendMessage(account,mailConfig);
return new Result(serverResult.isStart(),0 ,serverResult.getMsg());
} catch (RuntimeException e) {
logger.error(e.getMessage());

View File

@ -17,6 +17,6 @@ public interface MailConfigService {
ServerResult editMailConfig(MailConfig mailConfig);
ServerResult testSendMessage(Account account);
ServerResult testSendMessage(Account account,MailConfig mailConfig);
}

View File

@ -61,27 +61,8 @@ public class MailConfigServiceImpl implements MailConfigService {
}
@Override
public ServerResult testSendMessage(Account account) {
public ServerResult testSendMessage(Account account, MailConfig mailConfig) {
try {
MailConfig mailConfig = mailConfigDao.getMailConfig();
if (mailConfig.getSender()==null){
return new ServerResult(false,"发件人地址为空");
}
if (mailConfig.getPersonal()==null){
return new ServerResult(false,"发件人昵称为空");
}
if (mailConfig.getEmailSmtpHost()==null){
return new ServerResult(false,"服务器地址为空");
}
if (mailConfig.getEmailSmtpPort()==null){
return new ServerResult(false,"服务器端口号为空");
}
if (mailConfig.getUsername()==null){
return new ServerResult(false,"用户名为空");
}
if (mailConfig.getPassword()==null){
return new ServerResult(false,"密码为空");
}
String title = "测试邮件";
String content = "你好"+mailConfig.getTestMail()+"这是一封测试邮件";
account.setEmail(mailConfig.getTestMail());

View File

@ -10,7 +10,7 @@ alibaba.cloud.secret-key=****
# 应用服务 WEB 访问端口
server.port=8083
server.servlet.context-path=/api
logging.level.root=debug
logging.level.root=error
# Actuator Web 访问端口
management.server.port=8081
@ -24,9 +24,9 @@ spring.servlet.multipart.maxRequestSize=200MB
# 数据库dataSource
jdbc.driver=8zQIdS8RzOBmd4qRctgYdYM/fdvrjnIJHyQH1bD/jNs=
#服务器本地127.0.0.1
jdbc.urla=xW6OiZLo8/kYFd+0f9nXNXXZg17CJWnfoV5JrAnJaOAhvoLVW/PHqSV0jFnpOIVAxA0arcvd8KTK5pmV8Pi3bPJxQoH6zwkUve3efptPE0f+GUBKpacl+rFIuiDIGGARWhD3wSn+1Q8t+jGw15GlDz/ASsSv8SiOXSlZnsWSVKIbTqDgaMM1VA==
jdbc.url=xW6OiZLo8/kYFd+0f9nXNXXZg17CJWnfoV5JrAnJaOAhvoLVW/PHqSV0jFnpOIVAxA0arcvd8KTK5pmV8Pi3bPJxQoH6zwkUve3efptPE0f+GUBKpacl+rFIuiDIGGARWhD3wSn+1Q8t+jGw15GlDz/ASsSv8SiOXSlZnsWSVKIbTqDgaMM1VA==
#azure
jdbc.url=xW6OiZLo8/kiW6baGG4kKlxB11i7ytYuDXFc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