From 639b0a76a661e1e174847dd0bf41606b8f93fee9 Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期三, 12 二月 2025 09:53:30 +0800
Subject: [PATCH] #

---
 rsf-server/src/main/java/com/vincent/rsf/server/common/service/EmailService.java |   43 +++++++++++++++++++++++++++++++++++++++++++
 rsf-server/src/main/resources/application-dev.yml                                |   13 +++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/common/service/EmailService.java b/rsf-server/src/main/java/com/vincent/rsf/server/common/service/EmailService.java
new file mode 100644
index 0000000..6a377d3
--- /dev/null
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/common/service/EmailService.java
@@ -0,0 +1,43 @@
+package com.vincent.rsf.server.common.service;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.mail.MailException;
+import org.springframework.mail.javamail.JavaMailSender;
+import org.springframework.mail.javamail.MimeMessageHelper;
+import org.springframework.stereotype.Service;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+@Slf4j
+@Service
+public class EmailService {
+
+    @Value("${spring.mail.username}")
+    private String from;
+
+    @Autowired
+    private JavaMailSender mailSender;
+
+    public boolean sendVerificationEmail(String to, String verificationCode) {
+        try {
+            MimeMessage message = mailSender.createMimeMessage();
+            message.setFrom(from);
+            MimeMessageHelper helper = new MimeMessageHelper(message, true);
+
+            // 閭欢涓婚鍜屽唴瀹�
+            helper.setTo(to);
+            helper.setSubject("Email Verification Code");
+            helper.setText("Your verification code is: " + verificationCode);
+
+            mailSender.send(message);
+            return true;
+        } catch (MailException | MessagingException e) {
+            log.error(this.getClass().getSimpleName(), e);
+            return false;
+        }
+    }
+
+}
diff --git a/rsf-server/src/main/resources/application-dev.yml b/rsf-server/src/main/resources/application-dev.yml
index 890851d..be46a1d 100644
--- a/rsf-server/src/main/resources/application-dev.yml
+++ b/rsf-server/src/main/resources/application-dev.yml
@@ -43,6 +43,19 @@
       maxRequestSize: 100MB
   jmx:
     enabled: false
+  mail:
+    from: t1341870251@163.com
+    host: smtp.163.com
+    port: 465
+    username: t1731253606@163.com
+    password: xltys1995
+    properties:
+      mail:
+        smtp:
+          auth: true
+          ssl: true
+          socketFactory:
+            class: javax.net.ssl.SSLSocketFactory
 
 redis:
   host: 127.0.0.1

--
Gitblit v1.9.1