This commit is contained in:
clay 2020-12-19 22:25:34 +08:00
parent 51fe11a3a8
commit 5cadd58b25
3 changed files with 22 additions and 37 deletions

View File

@ -37,41 +37,7 @@ public class MailConfigController {
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);
ServerResult serverResult = mailConfigService.testSendMessage(account);
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,MailConfig mailConfig);
ServerResult testSendMessage(Account account);
}

View File

@ -61,8 +61,27 @@ public class MailConfigServiceImpl implements MailConfigService {
}
@Override
public ServerResult testSendMessage(Account account, MailConfig mailConfig) {
public ServerResult testSendMessage(Account account) {
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());