package com.njcn.web.utils;

import cn.hutool.core.io.FileUtil;
import cn.hutool.extra.mail.MailUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author wr
 * @description
 * @date 2024/3/11 14:32
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class EmailUtil {


   /**
    * 推送单邮件信息发送
    * @param to
    * @param title
    * @param content
    * @param isHtml
    */
    public void send(String to,String title,String content,Boolean isHtml) {
        if(isHtml){
            String s = FileUtil.readUtf8String("cs.html");
            content = s.replace("#{content}", content);
        }
        MailUtil.send(to, title, content, isHtml);
    }

    /**
     * 推送多个邮件信息
     * @param to
     * @param title
     * @param content
     * @param isHtml
     */
    public void sendMultiple(List<String> to,String title,String content,Boolean isHtml) {
        if(isHtml){
            String s = FileUtil.readUtf8String("cs.html");
            content = s.replace("#{content}", content);
        }
        MailUtil.send(to, title, content, isHtml);
    }
}
