mirror of
https://github.com/vran-dev/databasir.git
synced 2025-10-29 11:29:19 +08:00
add useTLS property to mail setting (#277)
* feat: add useSSL property to mail setting * feat: update frontend resource * feat: update submodule
This commit is contained in:
@@ -17,5 +17,7 @@ public class SystemEmailResponse {
|
||||
|
||||
private Boolean useSSL;
|
||||
|
||||
private Boolean useTls;
|
||||
|
||||
private LocalDateTime createAt;
|
||||
}
|
||||
|
||||
@@ -26,4 +26,7 @@ public class SystemEmailUpdateRequest {
|
||||
@NotNull
|
||||
private Boolean useSSL;
|
||||
|
||||
@NotNull
|
||||
private Boolean useTls;
|
||||
|
||||
}
|
||||
|
||||
@@ -24,16 +24,17 @@ public class SystemService {
|
||||
|
||||
public Optional<SystemEmailResponse> getEmailSetting() {
|
||||
return sysMailDao.selectOptionTopOne()
|
||||
.map(mail -> {
|
||||
SystemEmailResponse response = new SystemEmailResponse();
|
||||
response.setSmtpHost(mail.getSmtpHost());
|
||||
response.setSmtpPort(mail.getSmtpPort());
|
||||
response.setUsername(mail.getUsername());
|
||||
response.setCreateAt(mail.getCreateAt());
|
||||
response.setMailFrom(mail.getMailFrom());
|
||||
response.setUseSSL(mail.getUseSsl());
|
||||
return response;
|
||||
});
|
||||
.map(mail -> {
|
||||
SystemEmailResponse response = new SystemEmailResponse();
|
||||
response.setSmtpHost(mail.getSmtpHost());
|
||||
response.setSmtpPort(mail.getSmtpPort());
|
||||
response.setUsername(mail.getUsername());
|
||||
response.setCreateAt(mail.getCreateAt());
|
||||
response.setMailFrom(mail.getMailFrom());
|
||||
response.setUseSSL(mail.getUseSsl());
|
||||
response.setUseTls(mail.getUseTls());
|
||||
return response;
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteSystemEmail() {
|
||||
@@ -50,6 +51,7 @@ public class SystemService {
|
||||
sysMail.setUsername(request.getUsername());
|
||||
sysMail.setMailFrom(request.getMailFrom());
|
||||
sysMail.setUseSsl(request.getUseSSL());
|
||||
sysMail.setUseTls(request.getUseTls());
|
||||
|
||||
Optional<Integer> idOpt = sysMailDao.selectOptionTopOne().map(SysMail::getId);
|
||||
idOpt.ifPresent(sysMail::setId);
|
||||
|
||||
@@ -13,6 +13,7 @@ import javax.mail.internet.MimeMessage;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Properties;
|
||||
|
||||
@Component
|
||||
public class MailSender {
|
||||
@@ -54,11 +55,19 @@ public class MailSender {
|
||||
}
|
||||
sender.setUsername(properties.getUsername());
|
||||
sender.setPassword(properties.getPassword());
|
||||
Properties props = sender.getJavaMailProperties();
|
||||
props.put("mail.smtp.auth", "true");
|
||||
|
||||
if (properties.getUseSsl()) {
|
||||
sender.setProtocol("smtps");
|
||||
props.put("mail.smtp.ssl.enable", "true");
|
||||
} else {
|
||||
sender.setProtocol("smtp");
|
||||
}
|
||||
|
||||
if (properties.getUseTls()) {
|
||||
props.put("mail.smtp.starttls.enable", "true");
|
||||
}
|
||||
sender.setDefaultEncoding(StandardCharsets.UTF_8.name());
|
||||
return sender;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user