diff --git a/build.gradle.kts b/build.gradle.kts index 2214307..576a0cb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -38,7 +38,7 @@ dependencies { implementation("org.springframework.session:spring-session-data-redis") implementation("org.springframework.boot:spring-boot-starter-data-mongodb") implementation("org.springframework.boot:spring-boot-starter-mail") -// implementation("org.springframework.boot:spring-boot-starter-oauth2-authorization-server") + implementation("org.springframework.boot:spring-boot-starter-oauth2-authorization-server") testImplementation("org.springframework.security:spring-security-test") annotationProcessor("org.projectlombok:lombok") implementation("org.springframework.boot:spring-boot-starter-thymeleaf") diff --git a/src/main/java/fuck/manthe/nmsl/service/MailService.java b/src/main/java/fuck/manthe/nmsl/service/MailService.java new file mode 100644 index 0000000..f809b84 --- /dev/null +++ b/src/main/java/fuck/manthe/nmsl/service/MailService.java @@ -0,0 +1,7 @@ +package fuck.manthe.nmsl.service; + +public interface MailService { + void send(String to, String subject, String text); + + void sendResetPasswordEmail(String to, String resetSecret); +} diff --git a/src/main/java/fuck/manthe/nmsl/service/impl/MailServiceImpl.java b/src/main/java/fuck/manthe/nmsl/service/impl/MailServiceImpl.java new file mode 100644 index 0000000..0d62ec9 --- /dev/null +++ b/src/main/java/fuck/manthe/nmsl/service/impl/MailServiceImpl.java @@ -0,0 +1,31 @@ +package fuck.manthe.nmsl.service.impl; + +import fuck.manthe.nmsl.service.MailService; +import jakarta.annotation.Resource; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.stereotype.Service; + +@Service +public class MailServiceImpl implements MailService { + @Resource + JavaMailSender mailSender; + + @Value("${spring.application.name}") + String appName; + + @Override + public void send(String to, String subject, String text) { + SimpleMailMessage message = new SimpleMailMessage(); + message.setTo(to); + message.setSubject(subject); + message.setText(text); + mailSender.send(message); + } + + @Override + public void sendResetPasswordEmail(String to, String link) { + send(to, "重置密码 - " + appName, "请点击链接来重置密码 " + link); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index b867865..c286e00 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -5,6 +5,12 @@ spring: mongodb: # 数据库地址,如果gateway和主控搭建在同一个服务器上建议修改 uri: mongodb://localhost:27017/vape-share + mail: + # 发件邮箱设置 + host: example.com + port: 8888 + username: example@example.com + password: password # 数据库加密 # 实际部署的时候请务必修改这个,否则他人可能可以解密你的数据库 # openssl rand -base64 32