MrShi
2025-08-19 ff087240b3dee29ce4e14ad0836e76b9fdf312cf
server/src/main/java/com/doumee/service/common/EmailService.java
@@ -1,5 +1,6 @@
package com.doumee.service.common;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -14,6 +15,7 @@
import java.util.Map;
@Service
@Slf4j
public class EmailService {
    @Autowired
    private JavaMailSender javaMailSender;//注入JavaMailSender
@@ -44,6 +46,7 @@
                }
            }
    public boolean sendEmailWithImages(String toEmail, String title, Map<String,String> contentForm, List<String> imgList) {
        log.error("邮件开始发送============"+toEmail);
        try {
                AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
                context.refresh();
@@ -68,11 +71,13 @@
                }
            content += "</div></body><html>";
            helper.setText(content,true);
                log.error("邮件内容============"+content);
            javaMailSender.send(message);
                    System.out.println("邮件发送成功!");
                log.error("邮件发生成功============");
                    return true;
            } catch (Exception e) {
            e.printStackTrace();
            log.error("邮件发生成功============"+e.getMessage());
                    return false;
                }
            }