import com.matrixone.apps.domain.DomainObject;
import com.matrixone.apps.domain.DomainRelationship;
import com.matrixone.apps.domain.util.FrameworkException;
import com.matrixone.apps.domain.util.MqlUtil;
import matrix.db.Context;

import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.*;
import java.util.logging.Logger;

public class AegPublicAccountMailIntegrate_mxJPO {

    private static final Logger LOGGER = Logger.getLogger(AegPublicAccountMailIntegrate_mxJPO.class.getName());

    private static final String OperatingUserGroup  = "0007\u8425\u8fd0\u7ec4";
    private static final String ProcurementUserGroup = "0005\u91c7\u8d2d\u7ec4";
    private static final String QualityUserGroup = "0006\u8d28\u91cf\u7ec4";

    private static final String SEND_EMAIL = "aegplm@aeg-imc.com";
    private static final String SEND_PASSWORD = "Aeg-1887";
    private static final String SMTP_HOST = "smtp.partner.outlook.cn";
    private static final String SMTP_PORT = "587";

    public void updateApprovalInfo(Context context, String[] args) throws Exception {

        String routeId = args[0];
        String changeId = args[1];
        LOGGER.info("routeId ==> " + routeId);
        LOGGER.info("changeId ==> " + changeId);

        String getRouteType = "print bus " + routeId + " select type dump |";
        String routeType = MqlUtil.mqlCommand(context, getRouteType);
        LOGGER.info("routeType ==> " + routeType);

        if("Route".equals(routeType))
        {
            String getChangeType = "print bus " + changeId + " select type dump |";
            String changeType = MqlUtil.mqlCommand(context, getChangeType);

            String getRouteNodeInfo = "print bus " + routeId + " select from[Route Node].to.id dump |";
            String routeNodeInfo = MqlUtil.mqlCommand(context, getRouteNodeInfo);
            LOGGER.info("routeNodeInfo ==> " + routeNodeInfo);

            List<String> groupIdList = getGroupId(context);

            if(!"".equals(groupIdList))
            {
                if(routeNodeInfo.contains("|"))
                {
                    String[] routeNodeIdItem = routeNodeInfo.split("\\|");
                    LOGGER.info("routeNodeIdItem ==> " + routeNodeIdItem.toString());

                    for (int i = 0; i < routeNodeIdItem.length; i++) {
                        String itemId = routeNodeIdItem[i];
                        LOGGER.info("=========================");
                        LOGGER.info("routeNodeIdItemID ==> " + itemId);

                        for (int j = 0; j < groupIdList.size(); j++) {
                            LOGGER.info("groupId ===> " + groupIdList.get(j));

                            if(groupIdList.get(j).equals(itemId))
                            {
                                LOGGER.info("=====> " + groupIdList.get(j));
                                LOGGER.info("=====> " + itemId);
                                checkChangeAttrValue(context, j, changeType, changeId, routeId, itemId);
                            }
                        }
                    }

                    for (int i = 0; i < routeNodeIdItem.length; i++) {
                        String itemId = routeNodeIdItem[i];
                        LOGGER.info("=========================");
                        LOGGER.info("routeNodeIdItemID ==> " + itemId);

                        for (int j = 0; j < groupIdList.size(); j++) {
                            LOGGER.info("groupId ===> " + groupIdList.get(j));

                            if(groupIdList.get(j).equals(itemId))
                            {
                                replaceRouteNode(context, routeId, itemId, changeId);
                            }
                        }
                    }

                } else {
                    if(groupIdList.contains(routeNodeInfo))
                    {
                        for (int i = 0; i < groupIdList.size(); i++) {
                            if(groupIdList.get(i).equals(routeNodeInfo)){
                                checkChangeAttrValue(context, i, changeType, changeId, routeId, routeNodeInfo);
                            }
                        }

                        replaceRouteNode(context, routeId, routeNodeInfo, changeId);
                    }
                }
            }
        }
    }

    public void checkChangeAttrValue(Context context, Integer index, String changeType, String changeId, String routeId, String routeNodeInfo ) throws FrameworkException {
        boolean isFlag = false;

        if(index == 0) {
            if("Change Action".equals(changeType)){
                isFlag = attrInputVerification(context, changeId, "XP_ChangeAction_Ext.operate");
            } else {
                isFlag = attrInputVerification(context, changeId, "XP_ChangeRequest_Ext.operate");
            }

            if (!isFlag){
                MqlUtil.mqlCommand(context,"notice $1","\u8bf7\u4e3a\u8425\u8fd0\u5ba1\u6279\u4eba\u586b\u9009\u503c");
                throw new RuntimeException("\u8bf7\u4e3a\u8425\u8fd0\u5ba1\u6279\u4eba\u586b\u9009\u503c");
            }
        } else if (index == 1) {

            if("Change Action".equals(changeType)){
                isFlag = attrInputVerification(context, changeId, "XP_ChangeAction_Ext.quality");
            } else {
                isFlag = attrInputVerification(context, changeId, "XP_ChangeRequest_Ext.quality");
            }

            if (!isFlag){
                MqlUtil.mqlCommand(context,"notice $1","\u8bf7\u4e3a\u8d28\u91cf\u5ba1\u6279\u4eba\u586b\u9009\u503c");
                throw new RuntimeException("\u8bf7\u4e3a\u8d28\u91cf\u5ba1\u6279\u4eba\u586b\u9009\u503c");
            }
        } else if (index == 2) {

            if("Change Action".equals(changeType)){
                isFlag = attrInputVerification(context, changeId, "XP_ChangeAction_Ext.purchase");
            } else {
                isFlag = attrInputVerification(context, changeId, "XP_ChangeRequest_Ext.purchase");
            }

            if (!isFlag){
                MqlUtil.mqlCommand(context,"notice $1","\u8bf7\u4e3a\u91c7\u8d2d\u5ba1\u6279\u4eba\u586b\u9009\u503c");
                throw new RuntimeException("\u8bf7\u4e3a\u91c7\u8d2d\u5ba1\u6279\u4eba\u586b\u9009\u503c");
            }
        }
    }

    public Boolean attrInputVerification(Context context, String changeId, String queryProperties) throws FrameworkException {
        String getAttrValue = "print bus " + changeId + " select attribute[" + queryProperties + "].value dump |";
        LOGGER.info("getAttrValue ==> " + getAttrValue);
        String value = MqlUtil.mqlCommand(context, getAttrValue);

        LOGGER.info(" ====>attrValue " + value);

        if("".equals(value))
        {
            return false;
        }
        return true;
    }

    public void replaceRouteNode(Context context, String routeId, String itemId, String changeId){

        String getConnId = "query connection from " + routeId + " to " + itemId + " select id attribute[Route Sequence] attribute[Title] attribute[Route Instructions] attribute[Route Action] dump |";
        LOGGER.info("getConnId ==> " + getConnId);

        try {
            String connInfo = MqlUtil.mqlCommand(context, getConnId);

            String connId = connInfo.split("\\|")[1];
            String routeSequence = connInfo.split("\\|")[2];
            String title = connInfo.split("\\|")[3];
            String routeInstructions = connInfo.split("\\|")[4];
            String routeAction = connInfo.split("\\|")[5];

            LOGGER.info("connId ==> " + connId);
            LOGGER.info("routeSequence ==> " + routeSequence);
            LOGGER.info("title ==> " + title);
            LOGGER.info("routeInstructions ==> " + routeInstructions);
            LOGGER.info("routeAction ==> " + routeAction);

            String delConnId = "delete connection " + connId;
            MqlUtil.mqlCommand(context,delConnId);

            LOGGER.info("================================================");
            Map<String, List<String>> caMap = getCAAttrInfo(context, changeId);
            LOGGER.info(" ======>  2222222222");
            String publicAccountId = "";

            String getItemTitle = "print bus " + itemId + " select attribute[Title].value dump |";
            LOGGER.info("getItemTitle ==> " + getItemTitle);
            String itemTitle = MqlUtil.mqlCommand(context, getItemTitle);
            LOGGER.info("itemTitle ==> " + itemTitle);

            if(!"".equals(itemTitle))
            {
                if(itemTitle.contains("\u8425\u8fd0")){
                    List<String> list = caMap.get("operate");
                    publicAccountId = list.get(1);

                } else if(itemTitle.contains("\u91c7\u8d2d")){
                    List<String> list = caMap.get("purchase");
                    publicAccountId = list.get(1);

                } else if (itemTitle.contains("\u8d28\u91cf")) {
                    List<String> list = caMap.get("quality");
                    publicAccountId = list.get(1);
                }
            }

            if(publicAccountId != ""){
                DomainObject fromDomainObject = DomainObject.newInstance(context, routeId);
                DomainObject toDomainObject = DomainObject.newInstance(context, publicAccountId);
                DomainRelationship domainRelationship = DomainRelationship.connect(context, fromDomainObject, "Route Node", toDomainObject);

                Map<String, String> map = new HashMap<>();
                map.put("Route Sequence", routeSequence);
                map.put("Assignee Set Due Date","Yes");
                map.put("Template Task", "Yes");
                map.put("Route Action", "Approve");
                map.put("Title", title);
                map.put("Route Instructions", routeInstructions);
                map.put("Parallel Node Procession Rule", "All");
                map.put("Date Offset From", "Route Start Date");

                domainRelationship.setAttributeValues(context, map);
            }
        } catch (FrameworkException e) {
            throw new RuntimeException(e);
        }
    }

    public List<String> getGroupId(Context context){
        String getReplaceInfo = "temp query bus Group * * where 'attribute[Title].value == " + OperatingUserGroup + " || attribute[Title].value == " + ProcurementUserGroup + " || attribute[Title].value == " + QualityUserGroup + "' select id dump |";
        LOGGER.info("getReplaceId ==> " + getReplaceInfo);

        List<String> list = new ArrayList<>();
        try {
            String replaceInfo = MqlUtil.mqlCommand(context, getReplaceInfo);
            LOGGER.info("replaceInfo ==> " + replaceInfo);
            String[] replaceInfoSplit = replaceInfo.split("\n");

            if(replaceInfoSplit.length > 0)
            {
                for (String value : replaceInfoSplit)
                {
                    String itemId = value.split("\\|")[3];
                    list.add(itemId);
                    LOGGER.info("itemId ==> " + itemId);
                }
            }
        } catch (FrameworkException e) {
            throw new RuntimeException(e);
        }

        return list;
    }

    public Map<String, List<String>> getCAAttrInfo(Context context, String changeId) {
        Map<String, List<String>> map = new HashMap<>();

        try {
            String caAttrInfo = getChangeAttrInfo(context, changeId);

            if(caAttrInfo.contains("|") && !"".equals(caAttrInfo)) {
                String[] attrInfoSplit = caAttrInfo.split("\\|");

                for (int i = 0; i < attrInfoSplit.length; i++) {
                    List<String> list = new ArrayList<>();

                    LOGGER.info("attrInfoSplit[i] ==> " + attrInfoSplit[i]);

                    if(!"".equals(attrInfoSplit[i])){
                        String publicAccountEmailInfo = attrInfoSplit[i].split("_")[0];
                        String publicAccountInfo = attrInfoSplit[i].split("_")[1];
                        LOGGER.info("publicAccountEmailInfo ==> " + publicAccountEmailInfo);
                        LOGGER.info("publicAccountInfo ==> " + publicAccountInfo);

                        String getPublicAccountInfoIdInfo = "";

                        if(i == 2)
                        {
                            getPublicAccountInfoIdInfo = "temp query bus Person " + "PLM." +  publicAccountInfo + " - select id dump |";
                            LOGGER.info("getPublicAccountInfoIdInfo ==> " + getPublicAccountInfoIdInfo);
                        }else {
                            getPublicAccountInfoIdInfo = "temp query bus Person " + publicAccountInfo + ".PLM" + " - select id dump |";
                            LOGGER.info("getPublicAccountInfoIdInfo ==> " + getPublicAccountInfoIdInfo);
                        }

                        String publicAccountIdInfo = MqlUtil.mqlCommand(context, getPublicAccountInfoIdInfo);
                        LOGGER.info("publicAccountIdInfo ==> " + publicAccountIdInfo);

                        if(!"".equals(publicAccountIdInfo)){
                            String publicAccountId = publicAccountIdInfo.split("\\|")[3];

                            LOGGER.info("=========> " + publicAccountId);

                            list.add(publicAccountEmailInfo);
                            list.add(publicAccountId);

                            if(i == 0 && attrInfoSplit[i].contains("_")) {
                                map.put("purchase",list);
                            } else if(i == 1 && attrInfoSplit[i].contains("_")) {
                                map.put("quality",list);
                            } else if(i == 2 && attrInfoSplit[i].contains("_")) {
                                map.put("operate",list);
                            }

                            LOGGER.info("=====> 11111111111");
                        }
                    }
                }
            }
        } catch (FrameworkException e) {
            throw new RuntimeException(e);
        }

        return map;
    }

    public String getChangeAttrInfo(Context context, String changeId) throws FrameworkException {
        String getChangeType = "print bus " + changeId + " select type dump |";
        String changeType = MqlUtil.mqlCommand(context, getChangeType);

        String getChangeInfo = "";

        if("Change Action".equals(changeType)) {
            getChangeInfo = "print bus " + changeId + " select attribute[XP_ChangeAction_Ext.purchase].value attribute[XP_ChangeAction_Ext.quality].value attribute[XP_ChangeAction_Ext.operate].value dump |";
            LOGGER.info("getChangeInfo ==> " + getChangeInfo);

        } else {
            getChangeInfo = "print bus " + changeId + " select attribute[XP_ChangeRequest_Ext.purchase].value attribute[XP_ChangeRequest_Ext.quality].value attribute[XP_ChangeRequest_Ext.operate].value dump |";
            LOGGER.info("getChangeInfo ==> " + getChangeInfo);

        }

        String changeAttrInfo = MqlUtil.mqlCommand(context, getChangeInfo);
        return changeAttrInfo;
    }

    public void sendMail(Context context, String[] args) throws Exception {
        String inboxTaskId = args[0];
        String relId = args[1];
        System.out.println("===>" + inboxTaskId);
        System.out.println("===>" + relId);
        System.out.println("==========================");

        String publicAccountEmail = "";

        String getProjectType = "print bus " + inboxTaskId + " select from[Route Task].to.to[Object Route].from.type dump |";
        String projectType = MqlUtil.mqlCommand(context, getProjectType);

        if("Change Action".equals(projectType) || "Change Request".equals(projectType))
        {
            String getTaskTitle = "print bus " + inboxTaskId + " select attribute[Title] dump |";
            String Title = MqlUtil.mqlCommand(context, getTaskTitle);

            LOGGER.info("Title ==> " + Title);

            if (!"".equals(Title))
            {
                if(Title.contains("\u751f\u4ea7") || Title.contains("\u8d28\u91cf") || Title.contains("\u91c7\u8d2d"))
                {
                    String emailInfo = "";
                    boolean isFlag = false;

                    if(Title.contains("\u751f\u4ea7")) {

                        String  getObjInfo = "";

                        if("Change Action".equals(projectType)){
                            getObjInfo = "print bus " + inboxTaskId + " select from[Route Task].to.to[Object Route].from.attribute[XP_ChangeAction_Ext.operate] dump |";
                        } else {
                            getObjInfo = "print bus " + inboxTaskId + " select from[Route Task].to.to[Object Route].from.attribute[XP_ChangeRequest_Ext.operate] dump |";
                        }
                        String objInfo = MqlUtil.mqlCommand(context, getObjInfo);

                        LOGGER.info("objInfo ==> " + objInfo);

                        if(!"".equals(objInfo))
                        {
                            isFlag = true;

                            String privatePersonInfo = objInfo.split("_")[0] + "@aeg-imc.com";
                            publicAccountEmail = "plm." + objInfo.split("_")[1] + "@aeg-imc.com";
                            LOGGER.info("privatePersonInfo ==> " + privatePersonInfo);
                            LOGGER.info("publicAccountEmail ==> " + publicAccountEmail);

                            emailInfo = privatePersonInfo;
                        }
                    } else if (Title.contains("\u8d28\u91cf")) {

                        String  getObjInfo = "";

                        if("Change Action".equals(projectType)){
                            getObjInfo = "print bus " + inboxTaskId + " select from[Route Task].to.to[Object Route].from.attribute[XP_ChangeAction_Ext.quality] dump |";
                        } else {
                            getObjInfo = "print bus " + inboxTaskId + " select from[Route Task].to.to[Object Route].from.attribute[XP_ChangeRequest_Ext.quality] dump |";
                        }

                        String  objInfo = MqlUtil.mqlCommand(context, getObjInfo);

                        LOGGER.info("objInfo ==> " + objInfo);

                        if(!"".equals(objInfo) && objInfo.contains("_"))
                        {
                            isFlag = true;

                            String privatePersonInfo = objInfo.split("_")[0] + "@aeg-imc.com";
                            publicAccountEmail = objInfo.split("_")[1] + ".plm" + "@aeg-imc.com";
                            LOGGER.info("privatePersonInfo ==> " + privatePersonInfo);
                            LOGGER.info("publicAccountEmail ==> " + publicAccountEmail);

                            emailInfo = privatePersonInfo;
                        }
                    } else if (Title.contains("\u91c7\u8d2d")) {

                        String  getObjInfo = "";

                        if("Change Action".equals(projectType)){
                            getObjInfo = "print bus " + inboxTaskId + " select from[Route Task].to.to[Object Route].from.attribute[XP_ChangeAction_Ext.purchase] dump |";
                        } else {
                            getObjInfo = "print bus " + inboxTaskId + " select from[Route Task].to.to[Object Route].from.attribute[XP_ChangeRequest_Ext.purchase] dump |";
                        }
                        String objInfo = MqlUtil.mqlCommand(context, getObjInfo);

                        LOGGER.info("objInfo ==> " + objInfo);

                        if(!"".equals(objInfo))
                        {
                            isFlag = true;

                            String privatePersonInfo = objInfo.split("_")[0] + "@aeg-imc.com";
                            publicAccountEmail = objInfo.split("_")[1] + ".plm" + "@aeg-imc.com";
                            LOGGER.info("privatePersonInfo ==> " + privatePersonInfo);
                            LOGGER.info("publicAccountEmail ==> " + publicAccountEmail);

                            emailInfo = privatePersonInfo;
                        }
                    }

                    LOGGER.info("isFlag ==> " + isFlag);

                    if(isFlag)
                    {
                        String itemInfo = "";

                        if("Change Action".equals(projectType)){
                            String getItemInfo = "print bus " + inboxTaskId + " select from[Route Task].to.to[Object Route].from.name from[Route Task].to.to[Object Route].from.attribute[Synopsis] from[Route Task].to.to[Object Route].from.description  from[Route Task].to.owner from[Project Task].to.name dump |";
                            itemInfo = MqlUtil.mqlCommand(context, getItemInfo);
                        } else {
                            String getItemInfo = "print bus " + inboxTaskId + " select from[Route Task].to.to[Object Route].from.name from[Route Task].to.to[Object Route].from.attribute[Title] from[Route Task].to.to[Object Route].from.description  from[Route Task].to.owner from[Project Task].to.name dump |";
                            itemInfo = MqlUtil.mqlCommand(context, getItemInfo);
                        }

                        LOGGER.info("itemInfo ==> " + itemInfo);

                        if(!"".equals(itemInfo)){
                            String[] splitInfo = itemInfo.split("\\|");
                            Map<String, String> map = new HashMap<>();

                            LOGGER.info("splitInfo ==> " + splitInfo.length);
                            if(splitInfo.length == 5)
                            {
                                map.put("Synopsis", splitInfo[1]);
                                map.put("projectName", splitInfo[0]);
                                map.put("description", splitInfo[2]);
                                map.put("taskOwner", splitInfo[3]);
                                map.put("userName", splitInfo[4]);
                                map.put("publicAccountEmail",publicAccountEmail);
                            }
                            send(emailInfo, map);
                        }
                    }
                }
            }
        }
    }

    public void send(String emailInfo, Map<String, String> itemMap){

        LOGGER.info("=============> + <=================");

        LOGGER.info(itemMap.get("description"));
        LOGGER.info(itemMap.get("Synopsis"));

        Properties properties = new Properties();
        properties.put("mail.smtp.auth", "true");
        properties.put("mail.smtp.starttls.enable", "true");
        properties.put("mail.smtp.host", SMTP_HOST);
        properties.put("mail.smtp.port", SMTP_PORT);
        properties.put("mail.smtp.ssl.protocols", "TLSv1.2");

        Session session = Session.getInstance(properties,
                new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(SEND_EMAIL, SEND_PASSWORD);
                    }
                });
        session.setDebug(true);

        Message message = new MimeMessage(session);
        try {
            message.setFrom(new InternetAddress(SEND_EMAIL));
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(emailInfo));
            //message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("1654607107@qq.com"));

            String body = "<div style=\"text-align: center;margin-left:12px;margin-right: 12px;margin-top:100px;background-color:#005685;\n" +
                    "                    ;border-radius: 30px\">" +
                    " <div style=\"padding-top: 30px;padding-left: 50px;padding-right: 50px\">\n" +
                    "            <p style=\"text-align: center;color:azure;font-size: xx-large\">" + itemMap.get("projectName") + "</p>\n" +
                    "        </div>" +
                    "        <div style=\"display: flex;justify-content: center;align-items: center\">\n" +
                    "            <div style=\"padding-left: 30px;background-color: white;border-radius: 10px;height: 260px;min-width:400px;padding-top: 30px;\">\n" +
                    "                <p style=\"text-align: left;color: grey;font-size:large\">" + "\u4efb\u52a1\u540d\u79f0: " + itemMap.get("taskName") + "</p>\n" +
                    "                <p style=\"text-align: left;color: grey;font-size:large\">" + "\u4efb\u52a1\u63cf\u8ff0: " + itemMap.get("description") + "</p>\n" +
                    "                <p style=\"text-align: left;color: grey;font-size:large\">" + "\u4efb\u52a1\u5206\u914d\u4eba: " + itemMap.get("taskOwner") + "</p>\n" +
                    "                <p style=\"text-align: left;color: grey;font-size:large\">" + "\u4efb\u52a1\u6267\u884c\u4eba: " + itemMap.get("userName") + "</p>\n" +
                    "                <p style=\"text-align: left;color: grey;font-size:large\">" + "\u5ba1\u6279\u8d26\u53f7\u4e3a: " + itemMap.get("publicAccountEmail") + "</p>\n" +
                    "                <a href=\"https://plm.aegpm.com/3ddashboard\" style=\"font-size:medium\">查看任务</a>\n" +
                    "            </div>\n" +
                    "        </div>\n" +
                    " <div style=\" padding-top:10px;color: white;padding-left: 20px;padding-right: 20px\" >\n" +
                    "            <p>\u672c\u90ae\u4ef6\u53ca\u6240\u6709\u9644\u4ef6\u4ec5\u4f9b\u6536\u4ef6\u5730\u5740\u4e2d\u7684\u4e2a\u4eba\u6216\u5b9e\u4f53\u4f7f\u7528\uff0c\u8fd9\u4e9b\u5185\u5bb9\u5747\u5c5e\u673a\u5bc6\u4fe1\u606f\u5e76\u6216\u8bbe\u6709\u6743\u9650</p>\n" +
                    "        </div>\n" +
                    "        <div style=\"display: flex;justify-content: center;align-items: center;margin-bottom: 50px\">\n" +
                    "            <p style=\"text-align: left;margin-left:50px;margin-right: 50px;color:lightgray;font-size: small\">\u5982\u679c\u60a8\u4e0d\u662f\u4efb\u4f55\u6307\u5b9a\u7684\u6536\u4ef6\u4eba\u6216\u8bef\u6536\u5230\u672c\u90ae\u4ef6，<br>\n" +
                    "            (i) \u60a8\u4e0d\u80fd\u9605\u8bfb\u3001\u6cc4\u6f0f\u6216\u590d\u5236\u672c\u90ae\u4ef6；<br>\n" +
                    "            (ii) \u8bf7\u901a\u8fc7\u7535\u5b50\u90ae\u4ef6\u901a\u77e5\u60a8\u6536\u4ef6\u7684\u53d1\u4ef6\u4eba\u5e76\u5220\u9664\u672c\u90ae\u4ef6\u53ca\u6240\u6709\u9644\u4ef6；<br>\n" +
                    "            (iii) \u5bf9\u4e8e\u56e0\u4f7f\u7528\u6216\u4f9d\u636e\u672c\u90ae\u4ef6\u800c\u5f15\u8d77\u7684\u4efb\u4f55\u635f\u5931\u6216\u635f\u5bb3，Dassault Systemes \u6982\u4e0d\u8d1f\u8d23\u6216\u627f\u62c5\u8d23\u4efb。</p>\n" +
                    "        </div>\n" +
                    "    </div>"
                    ;
            message.setSubject("subject");
            message.setContent(body, "text/html;charset=utf-8");
            Transport.send(message);
        } catch (MessagingException e) {
            throw new RuntimeException();
        }
        System.out.println("Email sent successfully!");
    }
}
