package com.cftech.cms.SendEmail;

import com.cftech.core.util.StringUtils;
import com.cftech.core.util.SystemConfig;

import java.io.File;
import java.util.List;
import java.util.Set;

public class EmailSendMessageUtil {

    /**
     * 发送HTML专用，此发放执行了字体Calibri,大小11pt
     * @param files
     * @param toEmails
     * @param ccEmails
     * @param subjectName
     * @param content
     * @param fileName
     * @return
     */
    public static String [] sendMail(List<File> files, Set<String> toEmails, Set<String> ccEmails, String subjectName, String content, String fileName){
        String toMails = null;
        String ccMails = null;
        if(ccEmails!=null){
            ccMails= StringUtils.join(ccEmails.toArray(),",");
        }
        if(toEmails!=null){
            toMails= StringUtils.join(toEmails.toArray(),",");
        }
        content="<div style='font-family: Calibri;font-size: 11pt;'>"+content+"<div>";
       return EmailSenderWithAttach.sendAttachEmail(SystemConfig.p.getProperty("email.host"),
               SystemConfig.p.getProperty("email.from"),
               toMails,
               subjectName,content,files,SystemConfig.p.getProperty("email.username"),
               SystemConfig.p.getProperty("email.password"),"465",fileName,ccMails
              );
    }

    /**
     * 发送HTML专用，此发放执行了字体Calibri,大小11pt
     * @param files
     * @param toEmails
     * @param ccEmails
     * @param subjectName
     * @param content
     * @param fileNames
     * @return
     */
    public static String [] sendAttachMail(List<File> files, Set<String> toEmails, Set<String> ccEmails, String subjectName, String content, List<String> fileNames){
        String toMails = null;
        String ccMails = null;
        if(ccEmails!=null){
            ccMails= StringUtils.join(ccEmails.toArray(),",");
        }
        if(toEmails!=null){
            toMails= StringUtils.join(toEmails.toArray(),",");
        }
        content="<div style='font-family: Calibri;font-size: 11pt;'>"+content+"<div>";
        return EmailSenderWithAttach.sendAttachEmail(SystemConfig.p.getProperty("email.host"),
                SystemConfig.p.getProperty("email.from"),
                toMails,
                subjectName,content,files,SystemConfig.p.getProperty("email.username"),
                SystemConfig.p.getProperty("email.password"),"465",fileNames,ccMails
        );
    }
}
