yangys
2025-08-20 51054f0da5dd4718212064510fff045815388b90
blade-service/blade-mdm/src/main/java/org/springblade/mdm/commons/service/EmailService.java
@@ -15,49 +15,5 @@
@Service
@Slf4j
public class EmailService {
   @Autowired
   private JavaMailSender mailSender;
   public void sendSimpleEmail(String to, String subject, String text) {
      SimpleMailMessage message = new SimpleMailMessage();
      message.setTo(to);
      message.setSubject(subject);
      message.setText(text);
      message.setFrom("zhangxiaoxu@qianwen.ltd");
      mailSender.send(message);
      log.info("Simple email sent to: {}", to);
   }
   public void sendHtmlEmail(String to, String subject, String htmlContent)
      throws MessagingException {
      MimeMessage message = mailSender.createMimeMessage();
      MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
      helper.setTo(to);
      helper.setSubject(subject);
      helper.setText(htmlContent, true); // true 表示 HTML 内容
      helper.setFrom("zhangxiaoxu@qianwen.ltd");
      mailSender.send(message);
      log.info("HTML email sent to: {}", to);
   }
   public void sendEmailWithAttachment(String to, String subject, String text,
                              File attachment) throws MessagingException {
      MimeMessage message = mailSender.createMimeMessage();
      MimeMessageHelper helper = new MimeMessageHelper(message, true);
      helper.setTo(to);
      helper.setSubject(subject);
      helper.setText(text);
      helper.setFrom("noreply@example.com");
      // 添加附件
      FileSystemResource file = new FileSystemResource(attachment);
      helper.addAttachment(attachment.getName(), file);
      mailSender.send(message);
      log.info("Email with attachment sent to: {}", to);
   }
}