Skip to content

Commit

Permalink
feat: mail service (todo)
Browse files Browse the repository at this point in the history
  • Loading branch information
cubewhy committed Oct 27, 2024
1 parent 99798a6 commit 37a6bf4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/fuck/manthe/nmsl/service/MailService.java
Original file line number Diff line number Diff line change
@@ -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);
}
31 changes: 31 additions & 0 deletions src/main/java/fuck/manthe/nmsl/service/impl/MailServiceImpl.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
6 changes: 6 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 37a6bf4

Please sign in to comment.