MailController.java 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.ruoyi.demo.controller;
  2. import com.ruoyi.common.core.domain.R;
  3. import com.ruoyi.common.mail.utils.MailUtils;
  4. import lombok.RequiredArgsConstructor;
  5. import org.springframework.validation.annotation.Validated;
  6. import org.springframework.web.bind.annotation.GetMapping;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RestController;
  9. import java.io.File;
  10. /**
  11. * 邮件发送案例
  12. *
  13. * @author Michelle.Chung
  14. */
  15. @Validated
  16. @RequiredArgsConstructor
  17. @RestController
  18. @RequestMapping("/demo/mail")
  19. public class MailController {
  20. /**
  21. * 发送邮件
  22. *
  23. * @param to 接收人
  24. * @param subject 标题
  25. * @param text 内容
  26. */
  27. @GetMapping("/sendSimpleMessage")
  28. public R<Void> sendSimpleMessage(String to, String subject, String text) {
  29. MailUtils.sendText(to, subject, text);
  30. return R.ok();
  31. }
  32. /**
  33. * 发送邮件(带附件)
  34. *
  35. * @param to 接收人
  36. * @param subject 标题
  37. * @param text 内容
  38. * @param filePath 附件路径
  39. */
  40. @GetMapping("/sendMessageWithAttachment")
  41. public R<Void> sendMessageWithAttachment(String to, String subject, String text, String filePath) {
  42. MailUtils.sendText(to, subject, text, new File(filePath));
  43. return R.ok();
  44. }
  45. }