package com.izouma.jmrh.utils;

import org.simplejavamail.api.email.Email;
import org.simplejavamail.api.mailer.Mailer;
import org.simplejavamail.api.mailer.config.TransportStrategy;
import org.simplejavamail.email.EmailBuilder;
import org.simplejavamail.mailer.MailerBuilder;

public class MailUtils {

    public static void sendEmail(String subject, String text, String receiveEmail) {
        Mailer mailer = MailerBuilder
                .withSMTPServerHost("smtp.163.com")
                .withSMTPServerPort(465)
                .withSMTPServerUsername("jxjmrh2021@163.com")
                .withSMTPServerPassword("HRCQWDZWGRPJGODD")
                .withTransportStrategy(TransportStrategy.SMTPS)
                .trustingAllHosts(true)
                .withDebugLogging(true)
                .buildMailer();

        Email email = EmailBuilder.startingBlank()
                .from("江西军民融合公共服务平台", "jxjmrh2021@163.com")
                .to(receiveEmail)
                .cc("jxjmrh2021@163.com")
                .withSubject(subject)
                .withHTMLText(text)
                .buildEmail();

        mailer.sendMail(email);
    }


    public static void main(String[] args) throws Exception {
        MailUtils.sendEmail("您的账户正在申请修改密码", "<style>\n" +
                "        .container {\n" +
                "            width: 775px;\n" +
                "            background: linear-gradient(180deg, #FFCC72 0%, #FFF7EA 72%, #FFFFFF 100%);\n" +
                "        }\n" +
                "\n" +
                "        .top {\n" +
                "            height: 150px;\n" +
                "            position: relative;\n" +
                "        }\n" +
                "\n" +
                "        .logo {\n" +
                "            position: absolute;\n" +
                "            left: 0;\n" +
                "            right: 0;\n" +
                "            top: 0;\n" +
                "            bottom: 50px;\n" +
                "            margin: auto;\n" +
                "            width: 500px;\n" +
                "        }\n" +
                "\n" +
                "        .content {\n" +
                "            padding: 50px 100px;\n" +
                "            font-size: 28px;\n" +
                "            color: #666666;\n" +
                "            font-weight: bold;\n" +
                "        }\n" +
                "\n" +
                "        .content .code {\n" +
                "            color: #BF1616;\n" +
                "            font-size: 50px;\n" +
                "            background: rgba(191, 22, 22, 0.1);\n" +
                "            text-align: center;\n" +
                "            line-height: 100px;\n" +
                "            margin: 30px 0;\n" +
                "        }\n" +
                "    </style>\n" +
                "    <table align=\"center\">\n" +
                "        <tr>\n" +
                "            <td>\n" +
                "                <div class=\"container\">\n" +
                "                    <div class=\"top\"> <img class=\"logo\"\n" +
                "                            src=\"https://jxjmrh.oss-cn-hangzhou.aliyuncs.com/image/pc_logo%402x.png\" />\n" +
                "                    </div>\n" +
                "                    <div class=\"content\">您的验证码是\n" +
                "                        <div class=\"code\">4445</div>\n" +
                "                        2021-08-08 11:11:11前有效，<br>\n" +
                "                        请不要将验证码透露给他人\n" +
                "                    </div>\n" +
                "                </div>\n" +
                "            </td>\n" +
                "        </tr>\n" +
                "    </table>", "692949348@qq.com");
    }
}
