xusl 10 månader sedan
incheckning
4e95bb04b0

+ 38 - 0
.gitignore

@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store

+ 79 - 0
pom.xml

@@ -0,0 +1,79 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.springframework.boot</groupId>
+    <artifactId>spring-boot-starter-parent</artifactId>
+    <version>2.2.1.RELEASE</version>
+    <relativePath/> <!-- lookup parent from repository -->
+  </parent>
+  <groupId>com.jiayue</groupId>
+  <artifactId>wnn-eamil</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  <name>test</name>
+  <description>Jiayue project test</description>
+
+  <properties>
+    <java.version>1.8</java.version>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter-web</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.projectlombok</groupId>
+      <artifactId>lombok</artifactId>
+      <optional>true</optional>
+    </dependency>
+
+    <dependency>
+      <groupId>cn.hutool</groupId>
+      <artifactId>hutool-all</artifactId>
+      <version>5.0.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.poi</groupId>
+      <artifactId>poi-ooxml</artifactId>
+      <version>4.1.1</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter-mail</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter-thymeleaf</artifactId>
+    </dependency>
+    <!--        <dependency>-->
+    <!--            <groupId>org.apache.poi</groupId>-->
+    <!--            <artifactId>poi-ooxml-schemas</artifactId>-->
+    <!--            <version>3.17</version>-->
+    <!--        </dependency>-->
+
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter-test</artifactId>
+      <scope>test</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>org.junit.vintage</groupId>
+          <artifactId>junit-vintage-engine</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-maven-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </build>
+</project>

+ 11 - 0
src/main/java/com/jiayue/test/EmailApplication.java

@@ -0,0 +1,11 @@
+package com.jiayue.test;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class EmailApplication {
+    public static void main(String[] args) {
+        SpringApplication.run(EmailApplication.class, args);
+    }
+}

+ 445 - 0
src/main/java/com/jiayue/test/entity/EmailParam.java

@@ -0,0 +1,445 @@
+package com.jiayue.test.entity;
+
+public class EmailParam {
+    private String c0;
+
+    private String c1;
+
+    private String c2;
+
+    private String c3;
+
+    private String c4;
+
+    private String c5;
+
+    private String c6;
+
+    private String c7;
+
+    private String c8;
+
+    private String c9;
+
+    private String c10;
+
+    private String c11;
+
+    private String c12;
+
+    private String c13;
+
+    private String c14;
+
+    private String c15;
+
+    private String c16;
+
+    private String c17;
+
+    private String c18;
+
+    private String c19;
+
+    private String c20;
+
+    private String c21;
+
+    private String c22;
+
+    private String c23;
+
+    private String c24;
+
+    private String c25;
+
+    private String c26;
+
+    private String c27;
+
+    public void setC0(String c0) {
+        this.c0 = c0;
+    }
+
+    public void setC1(String c1) {
+        this.c1 = c1;
+    }
+
+    public void setC2(String c2) {
+        this.c2 = c2;
+    }
+
+    public void setC3(String c3) {
+        this.c3 = c3;
+    }
+
+    public void setC4(String c4) {
+        this.c4 = c4;
+    }
+
+    public void setC5(String c5) {
+        this.c5 = c5;
+    }
+
+    public void setC6(String c6) {
+        this.c6 = c6;
+    }
+
+    public void setC7(String c7) {
+        this.c7 = c7;
+    }
+
+    public void setC8(String c8) {
+        this.c8 = c8;
+    }
+
+    public void setC9(String c9) {
+        this.c9 = c9;
+    }
+
+    public void setC10(String c10) {
+        this.c10 = c10;
+    }
+
+    public void setC11(String c11) {
+        this.c11 = c11;
+    }
+
+    public void setC12(String c12) {
+        this.c12 = c12;
+    }
+
+    public void setC13(String c13) {
+        this.c13 = c13;
+    }
+
+    public void setC14(String c14) {
+        this.c14 = c14;
+    }
+
+    public void setC15(String c15) {
+        this.c15 = c15;
+    }
+
+    public void setC16(String c16) {
+        this.c16 = c16;
+    }
+
+    public void setC17(String c17) {
+        this.c17 = c17;
+    }
+
+    public void setC18(String c18) {
+        this.c18 = c18;
+    }
+
+    public void setC19(String c19) {
+        this.c19 = c19;
+    }
+
+    public void setC20(String c20) {
+        this.c20 = c20;
+    }
+
+    public void setC21(String c21) {
+        this.c21 = c21;
+    }
+
+    public void setC22(String c22) {
+        this.c22 = c22;
+    }
+
+    public void setC23(String c23) {
+        this.c23 = c23;
+    }
+
+    public void setC24(String c24) {
+        this.c24 = c24;
+    }
+
+    public void setC25(String c25) {
+        this.c25 = c25;
+    }
+
+    public void setC26(String c26) {
+        this.c26 = c26;
+    }
+
+    public void setC27(String c27) {
+        this.c27 = c27;
+    }
+
+    public boolean equals(Object o) {
+        if (o == this)
+            return true;
+        if (!(o instanceof EmailParam))
+            return false;
+        EmailParam other = (EmailParam)o;
+        if (!other.canEqual(this))
+            return false;
+        Object this$c0 = getC0(), other$c0 = other.getC0();
+        if ((this$c0 == null) ? (other$c0 != null) : !this$c0.equals(other$c0))
+            return false;
+        Object this$c1 = getC1(), other$c1 = other.getC1();
+        if ((this$c1 == null) ? (other$c1 != null) : !this$c1.equals(other$c1))
+            return false;
+        Object this$c2 = getC2(), other$c2 = other.getC2();
+        if ((this$c2 == null) ? (other$c2 != null) : !this$c2.equals(other$c2))
+            return false;
+        Object this$c3 = getC3(), other$c3 = other.getC3();
+        if ((this$c3 == null) ? (other$c3 != null) : !this$c3.equals(other$c3))
+            return false;
+        Object this$c4 = getC4(), other$c4 = other.getC4();
+        if ((this$c4 == null) ? (other$c4 != null) : !this$c4.equals(other$c4))
+            return false;
+        Object this$c5 = getC5(), other$c5 = other.getC5();
+        if ((this$c5 == null) ? (other$c5 != null) : !this$c5.equals(other$c5))
+            return false;
+        Object this$c6 = getC6(), other$c6 = other.getC6();
+        if ((this$c6 == null) ? (other$c6 != null) : !this$c6.equals(other$c6))
+            return false;
+        Object this$c7 = getC7(), other$c7 = other.getC7();
+        if ((this$c7 == null) ? (other$c7 != null) : !this$c7.equals(other$c7))
+            return false;
+        Object this$c8 = getC8(), other$c8 = other.getC8();
+        if ((this$c8 == null) ? (other$c8 != null) : !this$c8.equals(other$c8))
+            return false;
+        Object this$c9 = getC9(), other$c9 = other.getC9();
+        if ((this$c9 == null) ? (other$c9 != null) : !this$c9.equals(other$c9))
+            return false;
+        Object this$c10 = getC10(), other$c10 = other.getC10();
+        if ((this$c10 == null) ? (other$c10 != null) : !this$c10.equals(other$c10))
+            return false;
+        Object this$c11 = getC11(), other$c11 = other.getC11();
+        if ((this$c11 == null) ? (other$c11 != null) : !this$c11.equals(other$c11))
+            return false;
+        Object this$c12 = getC12(), other$c12 = other.getC12();
+        if ((this$c12 == null) ? (other$c12 != null) : !this$c12.equals(other$c12))
+            return false;
+        Object this$c13 = getC13(), other$c13 = other.getC13();
+        if ((this$c13 == null) ? (other$c13 != null) : !this$c13.equals(other$c13))
+            return false;
+        Object this$c14 = getC14(), other$c14 = other.getC14();
+        if ((this$c14 == null) ? (other$c14 != null) : !this$c14.equals(other$c14))
+            return false;
+        Object this$c15 = getC15(), other$c15 = other.getC15();
+        if ((this$c15 == null) ? (other$c15 != null) : !this$c15.equals(other$c15))
+            return false;
+        Object this$c16 = getC16(), other$c16 = other.getC16();
+        if ((this$c16 == null) ? (other$c16 != null) : !this$c16.equals(other$c16))
+            return false;
+        Object this$c17 = getC17(), other$c17 = other.getC17();
+        if ((this$c17 == null) ? (other$c17 != null) : !this$c17.equals(other$c17))
+            return false;
+        Object this$c18 = getC18(), other$c18 = other.getC18();
+        if ((this$c18 == null) ? (other$c18 != null) : !this$c18.equals(other$c18))
+            return false;
+        Object this$c19 = getC19(), other$c19 = other.getC19();
+        if ((this$c19 == null) ? (other$c19 != null) : !this$c19.equals(other$c19))
+            return false;
+        Object this$c20 = getC20(), other$c20 = other.getC20();
+        if ((this$c20 == null) ? (other$c20 != null) : !this$c20.equals(other$c20))
+            return false;
+        Object this$c21 = getC21(), other$c21 = other.getC21();
+        if ((this$c21 == null) ? (other$c21 != null) : !this$c21.equals(other$c21))
+            return false;
+        Object this$c22 = getC22(), other$c22 = other.getC22();
+        if ((this$c22 == null) ? (other$c22 != null) : !this$c22.equals(other$c22))
+            return false;
+        Object this$c23 = getC23(), other$c23 = other.getC23();
+        if ((this$c23 == null) ? (other$c23 != null) : !this$c23.equals(other$c23))
+            return false;
+        Object this$c24 = getC24(), other$c24 = other.getC24();
+        if ((this$c24 == null) ? (other$c24 != null) : !this$c24.equals(other$c24))
+            return false;
+        Object this$c25 = getC25(), other$c25 = other.getC25();
+        if ((this$c25 == null) ? (other$c25 != null) : !this$c25.equals(other$c25))
+            return false;
+        Object this$c26 = getC26(), other$c26 = other.getC26();
+        if ((this$c26 == null) ? (other$c26 != null) : !this$c26.equals(other$c26))
+            return false;
+        Object this$c27 = getC27(), other$c27 = other.getC27();
+        return !((this$c27 == null) ? (other$c27 != null) : !this$c27.equals(other$c27));
+    }
+
+    protected boolean canEqual(Object other) {
+        return other instanceof EmailParam;
+    }
+
+    public int hashCode() {
+        int PRIME = 59;
+        int result = 1;
+        Object $c0 = getC0();
+        result = result * 59 + (($c0 == null) ? 43 : $c0.hashCode());
+        Object $c1 = getC1();
+        result = result * 59 + (($c1 == null) ? 43 : $c1.hashCode());
+        Object $c2 = getC2();
+        result = result * 59 + (($c2 == null) ? 43 : $c2.hashCode());
+        Object $c3 = getC3();
+        result = result * 59 + (($c3 == null) ? 43 : $c3.hashCode());
+        Object $c4 = getC4();
+        result = result * 59 + (($c4 == null) ? 43 : $c4.hashCode());
+        Object $c5 = getC5();
+        result = result * 59 + (($c5 == null) ? 43 : $c5.hashCode());
+        Object $c6 = getC6();
+        result = result * 59 + (($c6 == null) ? 43 : $c6.hashCode());
+        Object $c7 = getC7();
+        result = result * 59 + (($c7 == null) ? 43 : $c7.hashCode());
+        Object $c8 = getC8();
+        result = result * 59 + (($c8 == null) ? 43 : $c8.hashCode());
+        Object $c9 = getC9();
+        result = result * 59 + (($c9 == null) ? 43 : $c9.hashCode());
+        Object $c10 = getC10();
+        result = result * 59 + (($c10 == null) ? 43 : $c10.hashCode());
+        Object $c11 = getC11();
+        result = result * 59 + (($c11 == null) ? 43 : $c11.hashCode());
+        Object $c12 = getC12();
+        result = result * 59 + (($c12 == null) ? 43 : $c12.hashCode());
+        Object $c13 = getC13();
+        result = result * 59 + (($c13 == null) ? 43 : $c13.hashCode());
+        Object $c14 = getC14();
+        result = result * 59 + (($c14 == null) ? 43 : $c14.hashCode());
+        Object $c15 = getC15();
+        result = result * 59 + (($c15 == null) ? 43 : $c15.hashCode());
+        Object $c16 = getC16();
+        result = result * 59 + (($c16 == null) ? 43 : $c16.hashCode());
+        Object $c17 = getC17();
+        result = result * 59 + (($c17 == null) ? 43 : $c17.hashCode());
+        Object $c18 = getC18();
+        result = result * 59 + (($c18 == null) ? 43 : $c18.hashCode());
+        Object $c19 = getC19();
+        result = result * 59 + (($c19 == null) ? 43 : $c19.hashCode());
+        Object $c20 = getC20();
+        result = result * 59 + (($c20 == null) ? 43 : $c20.hashCode());
+        Object $c21 = getC21();
+        result = result * 59 + (($c21 == null) ? 43 : $c21.hashCode());
+        Object $c22 = getC22();
+        result = result * 59 + (($c22 == null) ? 43 : $c22.hashCode());
+        Object $c23 = getC23();
+        result = result * 59 + (($c23 == null) ? 43 : $c23.hashCode());
+        Object $c24 = getC24();
+        result = result * 59 + (($c24 == null) ? 43 : $c24.hashCode());
+        Object $c25 = getC25();
+        result = result * 59 + (($c25 == null) ? 43 : $c25.hashCode());
+        Object $c26 = getC26();
+        result = result * 59 + (($c26 == null) ? 43 : $c26.hashCode());
+        Object $c27 = getC27();
+        return result * 59 + (($c27 == null) ? 43 : $c27.hashCode());
+    }
+
+    public String toString() {
+        return "EmailParam(c0=" + getC0() + ", c1=" + getC1() + ", c2=" + getC2() + ", c3=" + getC3() + ", c4=" + getC4() + ", c5=" + getC5() + ", c6=" + getC6() + ", c7=" + getC7() + ", c8=" + getC8() + ", c9=" + getC9() + ", c10=" + getC10() + ", c11=" + getC11() + ", c12=" + getC12() + ", c13=" + getC13() + ", c14=" + getC14() + ", c15=" + getC15() + ", c16=" + getC16() + ", c17=" + getC17() + ", c18=" + getC18() + ", c19=" + getC19() + ", c20=" + getC20() + ", c21=" + getC21() + ", c22=" + getC22() + ", c23=" + getC23() + ", c24=" + getC24() + ", c25=" + getC25() + ", c26=" + getC26() + ", c27=" + getC27() + ")";
+    }
+
+    public String getC0() {
+        return this.c0;
+    }
+
+    public String getC1() {
+        return this.c1;
+    }
+
+    public String getC2() {
+        return this.c2;
+    }
+
+    public String getC3() {
+        return this.c3;
+    }
+
+    public String getC4() {
+        return this.c4;
+    }
+
+    public String getC5() {
+        return this.c5;
+    }
+
+    public String getC6() {
+        return this.c6;
+    }
+
+    public String getC7() {
+        return this.c7;
+    }
+
+    public String getC8() {
+        return this.c8;
+    }
+
+    public String getC9() {
+        return this.c9;
+    }
+
+    public String getC10() {
+        return this.c10;
+    }
+
+    public String getC11() {
+        return this.c11;
+    }
+
+    public String getC12() {
+        return this.c12;
+    }
+
+    public String getC13() {
+        return this.c13;
+    }
+
+    public String getC14() {
+        return this.c14;
+    }
+
+    public String getC15() {
+        return this.c15;
+    }
+
+    public String getC16() {
+        return this.c16;
+    }
+
+    public String getC17() {
+        return this.c17;
+    }
+
+    public String getC18() {
+        return this.c18;
+    }
+
+    public String getC19() {
+        return this.c19;
+    }
+
+    public String getC20() {
+        return this.c20;
+    }
+
+    public String getC21() {
+        return this.c21;
+    }
+
+    public String getC22() {
+        return this.c22;
+    }
+
+    public String getC23() {
+        return this.c23;
+    }
+
+    public String getC24() {
+        return this.c24;
+    }
+
+    public String getC25() {
+        return this.c25;
+    }
+
+    public String getC26() {
+        return this.c26;
+    }
+
+    public String getC27() {
+        return this.c27;
+    }
+}

+ 31 - 0
src/main/java/com/jiayue/test/job/SpringDynamicCronTask.java

@@ -0,0 +1,31 @@
+package com.jiayue.test.job;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.scheduling.annotation.SchedulingConfigurer;
+import org.springframework.scheduling.config.ScheduledTaskRegistrar;
+import org.springframework.scheduling.support.CronTrigger;
+
+public class SpringDynamicCronTask implements SchedulingConfigurer {
+    private static final Logger log = LoggerFactory.getLogger(SpringDynamicCronTask.class);
+
+    private static String cron = "0/5 * * * * ?";
+
+    public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
+        scheduledTaskRegistrar.addTriggerTask(() -> log.error("dynamicCronTask is running..."), triggerContext -> {
+            CronTrigger cronTrigger = new CronTrigger(cron);
+            return cronTrigger.nextExecutionTime(triggerContext);
+        });
+    }
+
+    public SpringDynamicCronTask() {
+        (new Thread(() -> {
+            try {
+                Thread.sleep(15000L);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+            cron = "0/2 * * * * ?";
+        })).start();
+    }
+}

+ 17 - 0
src/main/java/com/jiayue/test/job/TestJob.java

@@ -0,0 +1,17 @@
+package com.jiayue.test.job;
+
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+@Component
+public class TestJob {
+    @Scheduled(cron = "0 0 * * * ?")
+    public void runfirst() {
+        System.out.println("********first job is ok******");
+    }
+
+    public static void main(String[] args) {
+        for (int i = 0; i < 100; i++)
+            System.out.println("test1.setC" + i + "(\"-99\");");
+    }
+}

+ 92 - 0
src/main/java/com/jiayue/test/mail/ApplicationRunnerImpl.java

@@ -0,0 +1,92 @@
+package com.jiayue.test.mail;
+
+import cn.hutool.core.io.resource.ResourceUtil;
+import cn.hutool.poi.excel.ExcelReader;
+import cn.hutool.poi.excel.ExcelUtil;
+import com.jiayue.test.entity.EmailParam;
+import java.util.Calendar;
+import java.util.List;
+import java.util.Map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ApplicationRunnerImpl implements ApplicationRunner {
+    private static final Logger log = LoggerFactory.getLogger(ApplicationRunnerImpl.class);
+
+    @Value("${spring.mail.username}")
+    private String from;
+
+    @Value("${templatePath}")
+    private String templatePath;
+
+    @Value("${filePath}")
+    private String filePath;
+
+    @Autowired
+    private SendEmailUtils sendEmailUtils;
+
+    public void run(ApplicationArguments args) throws Exception {
+        log.info("通过实现ApplicationRunner接口,在spring boot项目启动后执行一次读取文件并发送邮件");
+         ExcelReader reader = ExcelUtil.getReader(ResourceUtil.getStream(this.filePath));
+        Calendar cale = null;
+        cale = Calendar.getInstance();
+        int year = cale.get(1);
+        int month = cale.get(2);
+        List<Map<String, Object>> readAll = reader.readAll();
+        int index = 0;
+        for (Map<String, Object> map : readAll) {
+            index++;
+            if (index > 1)
+                try {
+                    EmailParam emailParam = new EmailParam();
+                    emailParam.setC1(getVal(map.get("c1")));
+                    emailParam.setC2(getVal(map.get("c2")));
+                    emailParam.setC3(getVal(map.get("c3")));
+                    emailParam.setC4(getVal(map.get("c4")));
+                    emailParam.setC5(getVal(map.get("c5")));
+                    emailParam.setC6(getVal(map.get("c6")));
+                    emailParam.setC7(getVal(map.get("c7")));
+                    emailParam.setC8(getVal(map.get("c8")));
+                    emailParam.setC9(getVal(map.get("c9")));
+                    emailParam.setC10(getVal(map.get("c10")));
+                    emailParam.setC11(getVal(map.get("c11")));
+                    emailParam.setC12(getVal(map.get("c12")));
+                    emailParam.setC13(getVal(map.get("c13")));
+                    emailParam.setC14(getVal(map.get("c14")));
+                    emailParam.setC15(getVal(map.get("c15")));
+                    emailParam.setC16(getVal(map.get("c16")));
+                    emailParam.setC17(getVal(map.get("c17")));
+                    emailParam.setC18(getVal(map.get("c18")));
+                    emailParam.setC19(getVal(map.get("c19")));
+                    emailParam.setC20(getVal(map.get("c20")));
+                    emailParam.setC21(getVal(map.get("c21")));
+                    emailParam.setC22(getVal(map.get("c22")));
+                    emailParam.setC23(getVal(map.get("c23")));
+                    emailParam.setC24(getVal(map.get("c24")));
+                    emailParam.setC25(getVal(map.get("c25")));
+                    emailParam.setC26(getVal(map.get("c26")));
+                    String[] to = { map.get("c2").toString() };
+                    if (to.length > 0 && !to[0].isEmpty()) {
+                        this.sendEmailUtils.thymeleafEmail(this.from, to, map.get("c1").toString() + year + "年"+month +"月份工资邮件", emailParam, this.templatePath);
+                        log.info(map.get("c2").toString() + ":Send Success!");
+                        Thread.sleep(1000L);
+                    }
+                } catch (Exception e) {
+                    log.error(map.get("c1").toString() + ":Send Faild!", e);
+                }
+        }
+        log.info("All mail sent!!!");
+    }
+
+    public String getVal(Object object) {
+        if (object != null)
+            return object.toString();
+        return "";
+    }
+}

+ 34 - 0
src/main/java/com/jiayue/test/mail/SendEmailUtils.java

@@ -0,0 +1,34 @@
+package com.jiayue.test.mail;
+
+import com.jiayue.test.entity.EmailParam;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.mail.javamail.JavaMailSender;
+import org.springframework.mail.javamail.MimeMessageHelper;
+import org.springframework.stereotype.Component;
+import org.thymeleaf.TemplateEngine;
+import org.thymeleaf.context.Context;
+import org.thymeleaf.context.IContext;
+
+@Component
+public class SendEmailUtils {
+    @Autowired
+    private JavaMailSender javaMailSender;
+
+    @Autowired
+    private TemplateEngine templateEngine;
+
+    public void thymeleafEmail(String from, String[] to, String subject, EmailParam emailParam, String template) throws MessagingException {
+        MimeMessage mimeMessage = this.javaMailSender.createMimeMessage();
+        MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true);
+        mimeMessageHelper.setFrom(from);
+        mimeMessageHelper.setTo(to);
+        mimeMessageHelper.setSubject(subject);
+        Context ctx = new Context();
+        ctx.setVariable("emailParam", emailParam);
+        String emailText = this.templateEngine.process(template, (IContext)ctx);
+        mimeMessageHelper.setText(emailText, true);
+        this.javaMailSender.send(mimeMessage);
+    }
+}

+ 16 - 0
src/main/resources/application.properties

@@ -0,0 +1,16 @@
+#mail
+spring.mail.host=smtp.263.net
+spring.mail.username=zhangxiao@jiayuepowertech.com
+#spring.mail.username=wangningning@jiayuepowertech.com
+spring.mail.password=zx654321
+#spring.mail.password=nn263095209
+#SSL֤  Socket    
+spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
+#ʹ  SMTPSЭ  465 ˿ 
+spring.mail.properties.mail.smtp.socketFactory.port=465
+spring.mail.properties.mail.smtp.auth=true
+spring.mail.properties.mail.smtp.starttls.enable=true
+spring.mail.properties.mail.smtp.starttls.required=true
+#html template path (resources/templates/email/template.html)
+templatePath=email/template
+filePath=C:/email/gzt.xlsx

+ 150 - 0
src/main/resources/templates/email/template.html

@@ -0,0 +1,150 @@
+<!DOCTYPE html>
+<html lang="en"
+      xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:th="http://www.thymeleaf.org">
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
+    <title>Siemens Sinnovation</title>
+    <style>
+        .button {
+            background-color: #4CAF50;
+            border-radius: 12px;
+            border: none;
+            color: white;
+            padding: 10px 25px;
+            text-align: center;
+            text-decoration: none;
+            display: inline-block;
+            font-size: 18px;
+            margin: 4px 2px;
+            cursor: pointer;
+            box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
+        }
+
+        .button:hover {
+            box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19);
+        }
+    </style>
+</head>
+<body style="margin: 0;padding: 0;">
+
+
+<table align="center" border="1" cellpadding="0" cellspacing="0" width="95%">
+    <tr>
+        <td>
+            <table align="center" border="0" cellpadding="0" cellspacing="0" width="100%"
+                   style="border-collapse: collapse;">
+<!--                <tr>-->
+<!--                    <td align="center" style="padding: 40px 0 30px 0;">-->
+<!--                        &lt;!&ndash;![](image/logo.png)&ndash;&gt;-->
+<!--                        <img src='cid:logoImage' alt='前途出国' title='前途出国' style='width:183px height:47.50px'>-->
+<!--                    </td>-->
+<!--                </tr>-->
+
+                <tr>
+                    <td bgcolor="#ffffff" style="padding: 0px 30px 20px 30px;">
+                        <h4 style="margin-top: 20px;">个人信息:</h4>
+                        <table border="0" cellpadding="0" cellspacing="0" width="100%">
+                            <tr>
+                                <td style="padding: 12px 0 3px 0">姓名:<span th:text="${emailParam.c1}"></span></td>
+                                <td style="padding: 12px 0 3px 0">邮箱:<span th:text="${emailParam.c2}"></span></td>
+                                <td style="padding: 12px 0 3px 0">入职日期:<span th:text="${emailParam.c3}"></span></td>
+                            </tr>
+                            <tr>
+                                <td style="padding: 12px 0 3px 0">参保地区:<span th:text="${emailParam.c0}"></span></td>
+                                <td style="padding: 12px 0 3px 0">是否试用期:<span th:text="${emailParam.c4}"></span></td>
+                                <td style="padding: 12px 0 3px 0">转正工资:<span th:text="${emailParam.c5}"></span></td>
+                            </tr>
+                        </table>
+                    </td>
+                </tr>
+                <tr>
+                    <td bgcolor="#ffffff" style="padding: 0px 30px 20px 30px">
+                        <h4>当月工资 :<span th:text="${emailParam.c6}" style="color: red;"></span></h4>
+                    </td>
+                </tr>
+                <tr>
+                    <td bgcolor="#ffffff" style="padding: 0px 30px 20px 30px">
+                        <h4>应加项目 :</h4>
+                        <table border="0" cellpadding="0" cellspacing="0" width="100%">
+                            <tr>
+                                <td style="padding: 12px 0 3px 0">电脑补助 :<span th:text="${emailParam.c7}"></span></td>
+                                <td style="padding: 12px 0 3px 0">其他补助 :<span th:text="${emailParam.c8}"></span></td>
+                                <td style="padding: 12px 0 3px 0">出差补助 :<span th:text="${emailParam.c9}"></span></td>
+<!--                                <td style="padding: 12px 0 3px 0;color: red;">人员费 :<span th:text="${emailParam.c27}" style="color: red;"></span></td>-->
+                            </tr>
+                            <tr>
+                                <td style="padding: 12px 0 3px 0">小计 :<span th:text="${emailParam.c10}"></span></td>
+                            </tr>
+                        </table>
+
+                    </td>
+                </tr>
+                <tr>
+                    <td bgcolor="#ffffff" style="padding: 0px 30px 20px 30px">
+                        <h4>应扣项目 :</h4>
+                        <table border="0" cellpadding="0" cellspacing="0" width="100%">
+                            <tr>
+                                <td style="padding: 12px 0 3px 0">缺勤天数 :<span th:text="${emailParam.c11}"></span></td>
+                                <td style="padding: 12px 0 3px 0">缺勤扣款 :<span th:text="${emailParam.c12}"></span></td>
+                                <td style="padding: 12px 0 3px 0">其他扣款 :<span th:text="${emailParam.c13}"></span></td>
+<!--                                <td style="padding: 12px 0 3px 0">人员费 :<span th:text="${emailParam.c27}"></span></td>-->
+                            </tr>
+                            <tr>
+                                <td style="padding: 12px 0 3px 0">小计 :<span th:text="${emailParam.c14}"></span></td>
+                            </tr>
+                        </table>
+                    </td>
+                </tr>
+                <tr>
+                    <td bgcolor="#ffffff" style="padding: 0px 30px 20px 30px">
+                        <h4>应发工资 :<span th:text="${emailParam.c15}" style="color: red;"></span></h4>
+                    </td>
+                </tr>
+                <tr>
+                    <td bgcolor="#ffffff" style="padding: 0px 30px 20px 30px">
+                        <h4>个人扣款保险费(注:预缴城市保险为次月) :</h4>
+                        <table border="0" cellpadding="0" cellspacing="0" width="100%">
+                            <tr>
+                                <td style="padding: 12px 0 3px 0">养老保险 :<span th:text="${emailParam.c16}"></span></td>
+                                <td style="padding: 12px 0 3px 0">医疗保险 :<span th:text="${emailParam.c17}"></span></td>
+                                <td style="padding: 12px 0 3px 0">失业保险 :<span th:text="${emailParam.c18}"></span></td>
+                                <td style="padding: 12px 0 3px 0">医保大额 :<span th:text="${emailParam.c19}"></span></td>
+                                <td style="padding: 12px 0 3px 0">住房公积金 :<span th:text="${emailParam.c20}"></span></td>
+                            </tr>
+                            <tr>
+                                <td style="padding: 12px 0 3px 0">小计 :<span th:text="${emailParam.c21}"></span></td>
+                            </tr>
+                        </table>
+                    </td>
+                </tr>
+                <tr>
+                    <td bgcolor="#ffffff" style="padding: 0px 30px 20px 30px">
+                        <h4>应税工资 :<span th:text="${emailParam.c22}" style="color: red;"></span></h4>
+                    </td>
+                </tr>
+                <tr>
+                    <td bgcolor="#ffffff" style="padding: 0px 30px 20px 30px">
+                        <h4>个人所得税 :<span th:text="${emailParam.c23}" style="color: red;"></span></h4>
+                    </td>
+                </tr>
+                <tr>
+                    <td bgcolor="#ffffff" style="padding: 0px 30px 20px 30px">
+                        <h4>工资发放方式:</h4>
+                        <table border="0" cellpadding="0" cellspacing="0" width="100%">
+                            <tr>
+                                <td style="padding: 12px 0 3px 0">公司已代发工资 :<span th:text="${emailParam.c24}" style="color: red;"></span></td>
+                                <td style="padding: 12px 0 3px 0">实发工资 :<span th:text="${emailParam.c25}" style="color: red;"></span></td>
+                                <td style="padding: 12px 0 3px 0">现金部分 :<span th:text="${emailParam.c26}" style="color: red;"></span></td>
+                            </tr>
+                        </table>
+                    </td>
+                </tr>
+
+            </table>
+        </td>
+    </tr>
+</table>
+</body>
+</html>

+ 38 - 0
src/test/java/org/example/AppTest.java

@@ -0,0 +1,38 @@
+package org.example;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest 
+    extends TestCase
+{
+    /**
+     * Create the test case
+     *
+     * @param testName name of the test case
+     */
+    public AppTest( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * @return the suite of tests being tested
+     */
+    public static Test suite()
+    {
+        return new TestSuite( AppTest.class );
+    }
+
+    /**
+     * Rigourous Test :-)
+     */
+    public void testApp()
+    {
+        assertTrue( true );
+    }
+}