邮件API

This commit is contained in:
2025-09-22 23:09:23 +08:00
parent d39c34dd95
commit e124006b81
2 changed files with 3 additions and 65 deletions

View File

@@ -11,6 +11,7 @@ import com.mini.capi.utils.FileUtils;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@@ -42,7 +43,7 @@ public class apiController {
private MailSentService mailSendService;
@GetMapping("/mailReceive")
@PostMapping("/mailReceive")
public ApiResult<?> mailReceive(String token) {
if (tokenBean.isValidToken(token)) {
return ApiResult.error(401, "无效的访问令牌");
@@ -52,7 +53,7 @@ public class apiController {
}
@GetMapping("/mailSend")
@PostMapping("/mailSend")
public ApiResult<?> mailSend(String token, String to, String cc, String subject, String content, String filePath) {
if (tokenBean.isValidToken(token)) {
return ApiResult.error(401, "无效的访问令牌");

View File

@@ -1,63 +0,0 @@
package com.mini.capi.sys.controller;
import com.mini.capi.biz.service.MailReceivedService;
import com.mini.capi.biz.service.MailSentService;
import jakarta.annotation.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.util.Map;
@RestController
@RequestMapping("/api/mail")
public class MailController {
@Resource
private MailReceivedService mailReceiveService;
@Resource
private MailSentService mailSendService;
/**
* 触发接收INBOX未读邮件
*/
@PostMapping("/receive")
public ResponseEntity<Map<String, String>> receiveMail() {
mailReceiveService.receiveUnreadMail();
return ResponseEntity.ok(Map.of("code", "200", "msg", "接收邮件任务已触发"));
}
/**
* 发送邮件(支持多收件人、多抄送、多附件)
* @param to 收件人多个用逗号分隔a@xxx.com,b@xxx.com
* @param cc 抄送(多个用逗号分隔,可选)
* @param subject 主题
* @param content 内容支持HTML
* @param files 附件(可选)
*/
@PostMapping("/send")
public ResponseEntity<Map<String, String>> sendMail(
@RequestParam("to") String to,
@RequestParam(value = "cc", required = false) String cc,
@RequestParam("subject") String subject,
@RequestParam("content") String content,
@RequestParam(value = "files", required = false) MultipartFile[] files) {
// 解析收件人(逗号分隔转数组)
String[] toAddresses = to.split(",");
// 解析抄送可选空则为null
String[] ccAddresses = cc != null && !cc.trim().isEmpty() ? cc.split(",") : null;
// 调用发送服务
mailSendService.sendMail(toAddresses, ccAddresses, subject, content, files);
return ResponseEntity.status(HttpStatus.CREATED)
.body(Map.of("code", "201", "msg", "邮件发送成功"));
}
}