-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
src/main/java/fuck/manthe/nmsl/service/impl/MailServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters