๐Ÿ‘จ‍๐Ÿ’ป kimtongting
article thumbnail

 

 

 

SMTP(Simple Mail Transfer Protocol) 

* SMTP๋ž€?

๐Ÿ“Simple Mail Transfer Protocol์˜ ์•ฝ์ž๋กœ ์ „์ž ๋ฉ”์ผ ์ „์†ก์„ ์œ„ํ•œ ํ‘œ์ค€ ํ”„๋กœํ† ์ฝœ์ด๋‹ค.

(์ด๋ฉ”์ผ์„ ์†ก์ˆ˜์‹ ํ•˜๋Š” ์„œ๋ฒ„๋ฅผ SMTP ์„œ๋ฒ„๋ผ๊ณ  ํ•œ๋‹ค)

 

* ์ž‘๋™๋ฐฉ์‹์€?

์ด๋ฉ”์ผ ํด๋ผ์ด์–ธํŠธ์™€ ๋ฉ”์ผ ์„œ๋ฒ„ ๊ฐ„์˜ ๋ฐ์ดํ„ฐ ๊ตํ™˜ ํ”„๋กœ์„ธ์Šค๋ฅผ ๊ฑฐ์ณ ๋™์ž‘ํ•œ๋‹ค.

  1. SMTP ์—ฐ๊ฒฐ: ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„ ๊ฐ„ TCP ์—ฐ๊ฒฐ๋กœ ์ด๋ฉ”์ผ ์ „์†ก ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹œ์ž‘
  2. ์ด๋ฉ”์ผ ๋ฐ์ดํ„ฐ ์ „์†ก: ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์ด๋ฉ”์ผ ํ—ค๋”(๋Œ€์ƒ ๋ฐ ์ œ๋ชฉ ์ค„ ํฌํ•จ), ์ด๋ฉ”์ผ ๋ณธ๋ฌธ, ๊ธฐํƒ€ ์ถ”๊ฐ€ ๊ตฌ์„ฑ ์š”์†Œ๋กœ ์ด๋ฃจ์–ด์ง„ ์‹ค์ œ ์ด๋ฉ”์ผ ์ฝ˜ํ…์ธ ์™€ ํ•จ๊ป˜ ์ผ๋ จ์˜ ๋ช…๋ น์„ ์„œ๋ฒ„์— ๋ณด๋ƒ„
  3. ๋ฉ”์ผ ์ „์†ก ์—์ด์ „ํŠธ(MTA): MTA๋Š” ์ˆ˜์‹ ์ž์˜ ์ด๋ฉ”์ผ ์ฃผ์†Œ ๋„๋ฉ”์ธ์„ ํ™•์ธํ•˜๊ณ  ๋ฐœ์‹ ์ž์™€ ๋‹ค๋ฅผ ๊ฒฝ์šฐ ์ˆ˜์‹ ์ž์˜ IP์ฃผ์†Œ๋ฅผ ์ฐพ๋„๋ก ๋„๋ฉ”์ธ ๋„ค์ž„ ์‹œ์Šคํ…œ(DNS)์— ์ฟผ๋ฆฌํ•œ๋‹ค. (์šฐ์ฒด๊ตญ์—์„œ ์šฐํŽธ๋ฌผ ์ˆ˜์‹ ์ž์˜ ์šฐํŽธ๋ฒˆํ˜ธ๋ฅผ ์กฐํšŒํ•˜๋Š” ๊ฒƒ๊ณผ ๊ฐ™๋‹ค.)
  4. ์—ฐ๊ฒฐ ์ข…๋ฃŒ: ๋ฐ์ดํ„ฐ ์ „์†ก์ด ์™„๋ฃŒ๋˜๋ฉด ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์„œ๋ฒ„์— ์•Œ๋ฆผ์„ ๋ณด๋‚ด๋ฉฐ ์„œ๋ฒ„๊ฐ€ ์—ฐ๊ฒฐ์„ ๋‹ซ๋Š”๋‹ค.
  5. (์ด๋•Œ ํด๋ผ์ด์–ธํŠธ๊ฐ€ SMTP ์—ฐ๊ฒฐ์„ ์ƒˆ๋กœ ์—ด์ง€ ์•Š๋Š” ํ•œ ์„œ๋ฒ„๋Š” ํด๋ผ์ด์–ธํŠธ๋กœ๋ถ€ํ„ฐ ์ด๋ฉ”์ผ ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€๋กœ ๋ฐ›์ง€ ์•Š๋Š”๋‹ค.)

* ์ฝ”๋“œ ๊ตฌํ˜„

public static void smtp(AlertModel alertModel) throws MessagingException, UnsupportedEncodingException {
        final String user = "blabla@gmail.com";   //๋ฐœ์‹ ๋ฉ”์ผ (์ด ์‚ฌ๋žŒ ๊ณ„์ •์œผ๋กœ ๋ณด๋‚ด๊ฒ ๋‹ค.)
        final String name = "[SMTP ๋ฉ”์ผ ์ „์†ก]";        
        final String password = "abcdefg1234";     //์•”ํ˜ธํ™”๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ ํ‚ค
        final String port = "587";
        final String bodyEncoding = "UTF-8"; //์ฝ˜ํ…์ธ  ์ธ์ฝ”๋”ฉ

        // SMTP ์„œ๋ฒ„ ์ •๋ณด๋ฅผ ์„ค์ •ํ•œ๋‹ค.
        Properties prop = new Properties();
        prop.put("mail.smtp.host", "smtp.gmail.com");
        prop.put("mail.smtp.port", port);
        prop.put("mail.smtp.auth", "true");
        prop.put("mail.smtp.ssl.trust", "smtp.gmail.com");
        prop.put("mail.smtp.starttls.enable", "true");
        prop.put("mail.smtp.ssl.protocols", "TLSv1.2");

        Session session = Session.getDefaultInstance(prop, new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(user, password);
            }
        });

        //๋ฉ”์‹œ์ง€ ํฌ๋งท์„ ๋‹ด๊ธฐ์œ„ํ•ด ์ƒ์„ฑ
        MimeMessage message = new MimeMessage(session);
        // ๋ฉ”์ผ ์ฝ˜ํ…์ธ  ์„ค์ •
        Multipart mParts = new MimeMultipart();
        MimeBodyPart mTextPart = new MimeBodyPart();
        //์ด๋ฉ”์ผ ํ—ค๋” ์„ค์ •
        message.setHeader("content-Type", "text/html");
        //๋ฐœ์‹ ์ž ์„ค์ •
        message.setFrom(new InternetAddress(user, name, bodyEncoding));
        // MIME ํƒ€์ž… ์„ค์ •
        MailcapCommandMap MailcapCmdMap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
        MailcapCmdMap.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
        MailcapCmdMap.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
        MailcapCmdMap.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
        MailcapCmdMap.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
        MailcapCmdMap.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");
        CommandMap.setDefaultCommandMap(MailcapCmdMap);

        //TODO: ์ˆ˜์‹ ์ž ๋ฉ”์ผ
        InternetAddress[] toSales = {
                new InternetAddress("sales@company.com"),
                new InternetAddress("support@company.com"),
                new InternetAddress("dmshin@company.com"),
                new InternetAddress("ljy@company.com"),
        };
        InternetAddress[] toSupport = {
                new InternetAddress("heo@company.com"),
                new InternetAddress("cs@company.com"),
                new InternetAddress("csb@company.com"),
                new InternetAddress("karstar@company.com"),
                new InternetAddress("joomsm@company.com"),
        };
        InternetAddress[] toCs = {
                new InternetAddress("jjh@company.com"),
                new InternetAddress("lhj@company.com"),
                new InternetAddress("shr@company.com"),
                new InternetAddress("ysy@company.com"),
                new InternetAddress("min@company.com"),
                new InternetAddress("sjcho@company.com"),
        };
        InternetAddress[] toSystem = {
                new InternetAddress("system@company.com"),
        };

        InternetAddress[] toTarget = {new InternetAddress(alertModel.getReceiver() + "@company.com")};
        StringBuffer sb = new StringBuffer();

        //๋ฉ”์‹œ์ง• ์˜ˆ์™ธ์ฒ˜๋ฆฌ
        try {
            message.setSubject("โ€ป์‹œ์Šคํ…œ ์ž๋™์•Œ๋ฆผ[" + alertModel.getService() + "] " + alertModel.getTitle()); //๋ฉ”์ผ ์ œ๋ชฉ์„ ์ž…๋ ฅ

            //NOTE: Table Start
            sb.append("<div style=\"width: 70%; margin:0 auto\">" +
                    "    <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"" +
                    "           style=\"max-width:100%;width:100%;font-family:'๋‚˜๋ˆ”๊ณ ๋”•',NanumGothic,'๋ง‘์€๊ณ ๋”•',Malgun Gothic,'๋‹์›€',Dotum,Helvetica,'Apple SD Gothic Neo',Sans-serif;background-color:#fff;-webkit-text-size-adjust:100%;text-align:left\">" +
                    "        <!-- Header -->" +
                    "        <tbody>");
            //NOTE: Header
            sb.append("<tr>" +
                    "            <td height=\"30\"></td>" +
                    "        </tr>" +
                    "        <tr>" +
                    "            <td style=\"padding-right:27px; padding-left:21px\">" +
                    "                <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" +
                    "                    <tbody>" +
                    "                    <tr>" +
                    "                        <td style=\"\" width=\"61\"><img" +
                    "                                src=\"https://company.com/img/logo2.png\" alt=\"UBCn\"" +
                    "                                width=\"61\" loading=\"lazy\"></td>" +
                    "                    </tr>" +
                    "                    </tbody>" +
                    "                </table>" +
                    "            </td>" +
                    "        </tr>" +
                    "        <tr>" +
                    "            <td height=\"13\"></td>" +
                    "        </tr>" +
                    "        <tr>" +
                    "            <td style=\"padding-right:27px; padding-left:18px;line-height:34px;font-size:29px;color:#424240;font-family:'๋‚˜๋ˆ”๊ณ ๋”•',NanumGothic,'๋ง‘์€๊ณ ๋”•',Malgun Gothic,'๋‹์›€',Dotum,Helvetica,'Apple SD Gothic Neo',Sans-serif;\">" +
                    "                ๋ฐฐ์น˜ ์‹œ์Šคํ…œ์—์„œ ๋ฐœ์†กํ•˜๋Š”<br><span style=\"color:#1ec800\">์ž๋™์•Œ๋ฆผ ์ž…๋‹ˆ๋‹ค.</span></td>" +
                    "        </tr>" +
                    "        <tr>" +
                    "            <td height=\"22\"></td>" +
                    "        </tr>" +
                    "        <tr>" +
                    "            <td height=\"1\" style=\"background-color: #e5e5e5;\"></td>" +
                    "        </tr>                    <!-- //Header -->");

            //์ด๋ฉ”์ผ ํ˜•์‹ ๊ตฌ๋ฌธ
            if (alertModel.getService().equalsIgnoreCase("QNA")) {
                alertModel.setTitle("[๋ฌธ์˜ํ•˜๊ธฐ] ํ™ˆํŽ˜์ด์ง€์— ์‹ ์ฒญ(๋ฌธ์˜)ํผ์ด ์ ‘์ˆ˜๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
                //NOTE: Content Table Header
                sb.append(Convenience.StringUtils.contentTableHeader());
                //NOTE: Content Table
                sb.append(
                        Convenience.StringUtils.contentTableRow("์‹œ๊ฐ„", alertModel.getSendDate()) +
                                Convenience.StringUtils.contentTableRow("์ด๋ฆ„", alertModel.getParamListMap().get(0).get("qnaName")) +
                                Convenience.StringUtils.contentTableRow("์—ฐ๋ฝ์ฒ˜", alertModel.getParamListMap().get(0).get("qnaPhone")) +
                                Convenience.StringUtils.contentTableRow("์ด๋ฉ”์ผ", alertModel.getParamListMap().get(0).get("qnaEmail")) +
                                Convenience.StringUtils.contentTableRow("์ œ๋ชฉ", alertModel.getParamListMap().get(0).get("qnaTitle")) +
                                Convenience.StringUtils.contentTableRow("๋‚ด์šฉ", alertModel.getParamListMap().get(0).get("qnaContent"))
                );
                //NOTE: Content Table Footer
                sb.append(Convenience.StringUtils.contentTableFooter());
            } else if (alertModel.getService().equalsIgnoreCase("welpoint")) {
                alertModel.setTitle("[์นด๋“œ๊ฒฐ์ œ์‹œ์Šคํ…œ ์ถฉ์ „๋ฐฐ์น˜์•Œ๋ฆผ]");
                //NOTE: Content subTitle
                sb.append(
                        Convenience.StringUtils.contentSubTitle("์นด๋“œ๊ฒฐ์ œ์‹œ์Šคํ…œ", "์ž๋™์ถฉ์ „", "์ •์ƒ์ฒ˜๋ฆฌ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
                );
            } else if (alertModel.getService().equalsIgnoreCase("MariaNode")) {
                alertModel.setTitle(alertModel.getService() + " ์ด์Šˆ ๋ฐœ์ƒ");
                //NOTE: Content subTitle
                sb.append(
                        Convenience.StringUtils.contentSubTitle("MariaDB", alertModel.getService(), "์˜ ๊ฐœ์ˆ˜๊ฐ€ 3๊ฐœ๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค. ์ ๊ฒ€ํ•„์š”")
                );
            } else if (alertModel.getService().equalsIgnoreCase("DDC")) {
                alertModel.setTitle(alertModel.getService() + " ์˜ค๋ฅ˜ ๋ฐœ์ƒ");
                //NOTE: Content subTitle
                sb.append(
                        Convenience.StringUtils.contentSubTitle("DDC", alertModel.getService(), "์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์Šต๋‹ˆ๋‹ค.")
                );
            } else if (alertModel.getService().equalsIgnoreCase("DDCDuplicateCheck")) {
                //NOTE: Content subTitle
                sb.append(
                        Convenience.StringUtils.contentSubTitle(alertModel.getParamListMap().get(1).get("PROCID") + " ๋‹˜",
                                alertModel.getContent() + "๋“ฑ๋ก์„ ํ•˜์…จ์Šต๋‹ˆ๋‹ค.",
                                "์ •์‚ฐ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด ํ•˜๊ธฐ ์ •๋ณด ๋ณ€๊ฒฝ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.")
                );
                //NOTE: Content Table Header
                sb.append(Convenience.StringUtils.contentTableHeader());
                //NOTE: Content Table
                for (int i = 0; i < alertModel.getParamListMap().size(); i++) {
                    sb.append(
                            Convenience.StringUtils.contentTableRow("๊ฐ€๋งน์ ์ •๋ณด", alertModel.getParamListMap().get(i).get("MERCHANTNAME")) +
                                    Convenience.StringUtils.contentTableRow("์‚ฌ์—…์ž๋ฒˆํ˜ธ", alertModel.getParamListMap().get(i).get("BUSINESSNO")) +
                                    Convenience.StringUtils.contentTableRow("์ค‘๋ณต ๋‹จ๋ง๊ธฐ", alertModel.getParamListMap().get(i).get("TERMINALID")) +
                                    Convenience.StringUtils.contentTableRow("์ค‘๋ณต Mall ID", alertModel.getParamListMap().get(i).get("PG_MERCH_NBR"))
                    );

                    if (i != alertModel.getParamListMap().size() - 1) {
                        sb.append(Convenience.StringUtils.contentEnterRow());
                    }
                }
                //NOTE: Content Table Footer
                sb.append(Convenience.StringUtils.contentTableFooter());
            } else if (alertModel.getService().equalsIgnoreCase("AdjustCheck")) {
                //NOTE: Content subTitle
                sb.append(
                        Convenience.StringUtils.contentSubTitle(alertModel.getParamListMap().get(1).get("PROCID") + " ๋‹˜",
                                alertModel.getContent() + "๋“ฑ๋ก์„ ํ•˜์…จ์Šต๋‹ˆ๋‹ค.",
                                "์ •์‚ฐ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด ํ•˜๊ธฐ ์ •๋ณด '์ž๋™๋งˆ๊ฐ'์˜ '๋งค์ผ์ •์‚ฐ'์œผ๋กœ ๋ณ€๊ฒฝ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.")
                );
                //NOTE: Content Table Header
                sb.append(Convenience.StringUtils.contentTableHeader());
                //NOTE: Content Table
                sb.append(
                        Convenience.StringUtils.contentTableRow("๊ฐ€๋งน์ ์ •๋ณด", alertModel.getParamListMap().get(0).get("MERCHANTNAME")) +
                                Convenience.StringUtils.contentTableRow("์‚ฌ์—…์ž๋ฒˆํ˜ธ", alertModel.getParamListMap().get(0).get("BUSINESSNO")) +
                                Convenience.StringUtils.contentTableRow("BIZ-TYPE", alertModel.getParamListMap().get(0).get("BIZTYPE")) +
                                Convenience.StringUtils.contentTableRow("๋‹จ๋ง๊ธฐ ID", alertModel.getParamListMap().get(0).get("TERMINALID")) +
                                Convenience.StringUtils.contentTableRow("VAN ID", alertModel.getParamListMap().get(0).get("PG_MERCH_NBR"))
                );
                //NOTE: Content Table Footer
                sb.append(Convenience.StringUtils.contentTableFooter());
            } else if (alertModel.getService().equalsIgnoreCase("PAYCO")) {
                alertModel.setTitle(alertModel.getService() + " ๋งค์ž… ์ž๋™ ์žฌ์ง„ํ–‰ ๊ณต์œ ");
                //NOTE: Content subTitle
                sb.append(
                        Convenience.StringUtils.contentSubTitle(alertModel.getService(),
                                "๋งค์ž…์ด ์žฌ์ง„ํ–‰ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.",
                                "์ •์ƒ์ฒ˜๋ฆฌ ์—ฌ๋ถ€ ์ตœ์ข… ์ ๊ฒ€์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.")
                );
            } else if (Convenience.stringUtils(alertModel.getService()).in("CSB", "TMN", "MYB")) {
                alertModel.setTitle(alertModel.getService() + " ๋งค์ž…์ฒ˜๋ฆฌ ์˜ค๋ฅ˜(์†ก์‹  ๋˜๋Š” ์ˆ˜์‹ )");
                //NOTE: Content subTitle
                sb.append(
                        Convenience.StringUtils.contentSubTitle(alertModel.getService(),
                                "๋งค์ž… ์˜ค๋ฅ˜(์†ก / ์ˆ˜์‹ )๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์Šต๋‹ˆ๋‹ค.",
                                "๋ฐฐ์น˜ ํ™•์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.")
                );
            } else if (alertModel.getService().equalsIgnoreCase("prepayUnregisteredTidCheck")) {
                //NOTE: Content subTitle
                sb.append(
                        Convenience.StringUtils.contentSubTitle(alertModel.getTitle(),
                                alertModel.getContent(),
                                "ํ™•์ธํ•˜์‹  ํ›„, ์ •๋ณด ๋“ฑ๋ก ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค."
                        )
                );

                //NOTE: Content Table Header
                sb.append(Convenience.StringUtils.contentTableHeader());

                sb.append("" +
                        "<table cellspacing=\"0\" width=\"100%\" style=\"table-layout: fixed; margin-top: 16px; border: 1px solid rgb(219, 219, 219); border-collapse: collapse; color: rgb(85, 85, 85); font-family: ๋‚˜๋ˆ”๊ณ ๋”•, NanumGothic, sans-serif; font-size: 12px; line-height: 18px;\"> \n" +
                        "         <thead style=\"box-sizing: border-box;\">" +
                        "               <tr style=\"box-sizing: border-box;\">" +
                        "                       <th colspan=\"1\" rowspan=\"1\" style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle; background: rgb(245, 245, 247);\"> ๋‹จ๋ง๊ธฐ ID </th>" +
                        "                       <th colspan=\"1\" rowspan=\"1\" style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle; background: rgb(245, 245, 247);\"> ๊ฐ€๋งน์ ๋ฒˆํ˜ธ </th>" +
                        "               </tr>" +
                        "         </thead> \n" +
                        "         <tbody style=\"box-sizing: border-box;\">");

                //NOTE: Content Table
                for (int i = 0; i < alertModel.getParamListMap().size(); i++) {
                    sb.append("         <tr style=\"box-sizing: border-box;\">" +
                            "               <td style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle;\">" + alertModel.getParamListMap().get(i).get("TRML_ID") + " </td>" +
                            "               <td style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle;\">" + alertModel.getParamListMap().get(i).get("MERCH_NBR") + " </td>" +
                            "           </tr>");

                }

                sb.append("         </tbody>" +
                        "</table>");

                //NOTE: Content Table Footer
                sb.append(Convenience.StringUtils.contentTableFooter());
            } else if (alertModel.getService().equalsIgnoreCase("KakaoAlertProcess")) {
                alertModel.setTitle(alertModel.getService() + " ์ด์ƒ ์•Œ๋ฆผ");
                //NOTE: Content subTitle
                sb.append(
                        Convenience.StringUtils.contentSubTitle(alertModel.getContent(),
                                "ํ”„๋กœ์„ธ์Šค ๋ฏธ๋™์ž‘",
                                "ํ”„๋กœ์„ธ์Šค ํ™•์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.")
                );
            } else if (alertModel.getService().equalsIgnoreCase("KakaoResponse")) {
                alertModel.setTitle(alertModel.getService() + " ์ด์ƒ ์•Œ๋ฆผ");
                //NOTE: Content subTitle
                sb.append(
                        Convenience.StringUtils.contentSubTitle("์นด์นด์˜ค ์•Œ๋ฆผํ†ก API ์—์„œ ERR ์‘๋‹ต์„ ๋ณด๋ƒˆ์Šต๋‹ˆ๋‹ค.",
                                alertModel.getContent(),
                                "ํ”„๋กœ์„ธ์Šค ํ™•์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.")
                );
            } else if (alertModel.getService().equalsIgnoreCase("vmDiskUsageCheck")) {
                //NOTE: Content subTitle
                sb.append(
                        Convenience.StringUtils.contentSubTitle("๋ฆฌํฌํŠธ",
                                alertModel.getTitle(),
                                "๋ฐœ์†ก๋˜์—ˆ์Šต๋‹ˆ๋‹ค."
                        )
                );

                //NOTE: Content Table Header
                sb.append(Convenience.StringUtils.contentTableHeader());
                sb.append("" +
                        "<table cellspacing=\"0\" width=\"100%\" style=\"table-layout: fixed; margin-top: 16px; border: 1px solid rgb(219, 219, 219); border-collapse: collapse; color: rgb(85, 85, 85); font-family: ๋‚˜๋ˆ”๊ณ ๋”•, NanumGothic, sans-serif; font-size: 12px; line-height: 18px;\"> \n" +
                        "         <thead style=\"box-sizing: border-box;\">" +
                        "               <tr style=\"box-sizing: border-box;\">" +
                        "                       <th colspan=\"1\" rowspan=\"1\" style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle; background: rgb(245, 245, 247);\"> Host IP </th>" +
                        "                       <th colspan=\"1\" rowspan=\"1\" style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle; background: rgb(245, 245, 247);\"> ์„œ๋น„์Šค </th>" +
                        "                       <th colspan=\"1\" rowspan=\"1\" style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle; background: rgb(245, 245, 247);\"> ํŒŒํ‹ฐ์…˜ </th>" +
                        "                       <th colspan=\"1\" rowspan=\"1\" style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle; background: rgb(245, 245, 247);\"> ํ• ๋‹น๊ฒฝ๋กœ </th>" +
                        "                       <th colspan=\"1\" rowspan=\"1\" style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle; background: rgb(245, 245, 247);\"> ํ• ๋‹น์šฉ๋Ÿ‰ </th>" +
                        "                       <th colspan=\"1\" rowspan=\"1\" style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle; background: rgb(245, 245, 247);\"> ์‚ฌ์šฉ์ค‘ </th>" +
                        "                       <th colspan=\"1\" rowspan=\"1\" style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle; background: rgb(245, 245, 247);\"> ์‚ฌ์šฉ๋Ÿ‰(%) </th>" +
                        "                       <th colspan=\"1\" rowspan=\"1\" style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle; background: rgb(245, 245, 247);\"> ์ด ๋ฉ”๋ชจ๋ฆฌ </th>" +
                        "                       <th colspan=\"1\" rowspan=\"1\" style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle; background: rgb(245, 245, 247);\"> free ๋ฉ”๋ชจ๋ฆฌ </th>" +
                        "                       <th colspan=\"1\" rowspan=\"1\" style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle; background: rgb(245, 245, 247);\"> ๋‚จ์€ ๋ฉ”๋ชจ๋ฆฌ </th>" +
                        "               </tr>" +
                        "         </thead> \n" +
                        "         <tbody style=\"box-sizing: border-box;\">");
                //NOTE: Content Table
                for (int i = 0; i < alertModel.getParamListMap().size(); i++) {
                    sb.append("         <tr style=\"box-sizing: border-box;\">" +
                            "               <td style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); vertical-align: middle;\">" + alertModel.getParamListMap().get(i).get("host") + " </td>" +
                            "               <td style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); vertical-align: middle;\">" + alertModel.getParamListMap().get(i).get("service") + " </td>" +
                            "               <td style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); vertical-align: middle;\">" + alertModel.getParamListMap().get(i).get("partition") + " </td>" +
                            "               <td style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); vertical-align: middle;\">" + alertModel.getParamListMap().get(i).get("path") + " </td>" +
                            "               <td style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle;\">" + alertModel.getParamListMap().get(i).get("size") + " </td>" +
                            "               <td style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle;\">" + alertModel.getParamListMap().get(i).get("used") + " </td>" +
                            "               <td style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle;\">" + alertModel.getParamListMap().get(i).get("percent") + " </td>" +
                            "               <td style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle;\">" + alertModel.getParamListMap().get(i).get("MemTotal") + " </td>" +
                            "               <td style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle;\">" + alertModel.getParamListMap().get(i).get("MemFree") + " </td>" +
                            "               <td style=\"box-sizing: border-box; padding: 5px 10px; border: 1px solid rgb(238, 238, 240); text-align: center; vertical-align: middle;\">" + alertModel.getParamListMap().get(i).get("MemAvailable") + " </td>" +
                            "           </tr>");

                }
                sb.append("         </tbody>" +
                        "</table>");

                //NOTE: Content Table Footer
                sb.append(Convenience.StringUtils.contentTableFooter());
            }
            //์ •์  ๋ฆฌ์†Œ์Šค

            //NOTE: Footer
            sb.append(
                    "<!-- footer -->" +
                            "                                <tr>" +
                            "                                    <td height=\"20\"></td>" +
                            "                                </tr>" +
                            "        <tr>" +
                            "            <td style=\"padding-top:26px;padding-left:21px;padding-right:21px;padding-bottom:13px;background:#f9f9f9;font-size:12px;font-family:'๋‚˜๋ˆ”๊ณ ๋”•',NanumGothic,'๋ง‘์€๊ณ ๋”•',Malgun Gothic,'๋‹์›€',Dotum,Helvetica,'Apple SD Gothic Neo',Sans-serif;color:#696969;line-height:17px\">" +
                            "                ๋ณธ ๋ฉ”์ผ์€ ๋ฐœ์‹ ์ „์šฉ ์ž…๋‹ˆ๋‹ค. ooweat ์„œ๋น„์Šค๊ด€๋ จ ๊ถ๊ธˆํ•˜์‹  ์‚ฌํ•ญ์€" +
                            "                <a href=\"http://company.com\" style=\"color:#696969;font-weight:bold;text-decoration:underline\" rel=\"noreferrer noopener\"" +
                            "                    target=\"_blank\"> ํ™ˆํŽ˜์ด์ง€</a>์—์„œ ํ™•์ธํ•ด์ฃผ์„ธ์š”." +
                            "            </td>" +
                            "        </tr>" +
                            "        <tr>" +
                            "            <td style=\"padding-left:21px;padding-right:21px;padding-bottom:57px;background:#f9f9f9;font-size:12px;font-family:Helvetica;color:#696969;line-height:17px\">" +
                            "                Copyright โ“’ <strong>ooweat</strong> Corp. All Rights Reserved." +
                            "            </td>" +
                            "        </tr>                    <!-- //footer -->   ");
            //NOTE: Table End
            sb.append("        </tbody>" +
                    "    </table>" +
                    "</div>");

            if (Convenience.stringUtils(alertModel.getReceiver()).in("sales", "support", "cs", "system")) {
                switch (alertModel.getReceiver()) {
                    case "sales":
                        message.addRecipients(Message.RecipientType.TO, toSales); //๋ฐ›๋Š” ์ด
                        message.addRecipients(Message.RecipientType.CC, toSystem); //์ฐธ์กฐ
                        break;
                    case "support":
                        message.addRecipients(Message.RecipientType.TO, toSupport); //๋ฐ›๋Š” ์ด
                        message.addRecipients(Message.RecipientType.CC, toSystem); //์ฐธ์กฐ
                        break;
                    case "cs":
                        message.addRecipients(Message.RecipientType.TO, toCs); //๋ฐ›๋Š” ์ด
                        message.addRecipients(Message.RecipientType.CC, toSystem); //์ฐธ์กฐ
                        break;
                    case "system":
                        message.addRecipients(Message.RecipientType.TO, toSystem); //๋ฐ›๋Š” ์ด
                        break;
                }
            } else {
                message.addRecipients(Message.RecipientType.TO, toTarget);
            }

            mTextPart.setText(sb.toString(), bodyEncoding, "html");
            mParts.addBodyPart(mTextPart);
            message.setContent(mParts);
            Transport.send(message);
            log.info("SEND: {}", "OK");

        } catch (SendFailedException e) {
            message.addRecipients(Message.RecipientType.TO, toSystem); //๋ฐ›๋Š” ์ด
            message.setSubject("โ€ป๋ฉ”์ผ๋ฐœ์†ก์‹คํŒจ[" + alertModel.getService() + "] " + alertModel.getTitle());
            sb.append(
                    alertModel.toString() + " <br> \n"
                            + "์ˆ˜์‹ ์ž์˜ ์‚ฌ์œ ๋กœ ๋ฉ”์ผ ๋ฐœ์†ก์„ ์‹คํŒจํ•˜์˜€์Šต๋‹ˆ๋‹ค. <br> \n"
                            + "</td></tr>"
                            + "<tr>"
                            + "<td style=\"margin:0; padding:0; height:24px; background-color: white;\"></td></tr><tr><td style=\"margin:0; background-color: white; padding:0 0 0; font-size:14px; letter-spacing:-1px; color:#000000; font-family:'Malgun Gothic', '๋ง‘์€๊ณ ๋”•', dotum,'๋‹์›€',sans-serif; line-height:24px;\">\n<br>\n"
            );
            mTextPart.setText(sb.toString(), bodyEncoding, "html");
            mParts.addBodyPart(mTextPart);
            message.setContent(mParts);
            Transport.send(message);
            log.error("SEND: {}", "FAIL // ์ˆ˜์‹ ์ž์˜ ์‚ฌ์œ ๋กœ ๋ฐœ์†ก๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.");
        } catch (AddressException e) {
            e.printStackTrace();
            log.error("SEND: {}", "FAIL // ์ฃผ์†Œ๊ฐ€ ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.");
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }

 

 

 

๋ฐ˜์‘ํ˜•
profile

๐Ÿ‘จ‍๐Ÿ’ป kimtongting

@kimtongting ์ž…๋‹ˆ๋‹ค

ํฌ์ŠคํŒ…์ด ์ข‹์•˜๋‹ค๋ฉด "์ข‹์•„์š”โค๏ธ" ๋˜๋Š” "๊ตฌ๋…๐Ÿ‘๐Ÿป" ํ•ด์ฃผ์„ธ์š”!