1、springboot有专门针对邮件的模块直接引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
2、添加参数配置
## 邮箱配置
spring:
mail:
host: mail.test.abc #发送邮件服务器
username: xxxx #发送邮件的邮箱地址
password: xxxx
default-encoding: utf-8
properties:
mail:
smtp:
port: 25
ssl:
trust: mail.test.abc
starttls:
enable: true
required: true
3、发送邮件的方法
@Autowired
private JavaMailSender mailSender;
public void sendEmail(){
String presentDate = "20210401";
String secondPresentDate = "20200331";
String date = presentDate.substring(0,4)+"年"+presentDate.substring(4,6)+"月"+presentDate.substring(6,8)+"日";
Map<String, String> map = sheet3DataMap.get(presentDate);
Map<String, String> secondPresentMap = sheet3DataMap.get(secondPresentDate);
String stockContent = "";
if(map.get("sh_idx") != null && secondPresentMap.get("sh_idx") != null){
double sh_idx = Double.parseDouble(map.get("sh_idx"));
double sz_idx = Double.parseDouble(map.get("sz_idx"));
double cyb_idx = Double.parseDouble(map.get("cyb_idx"));
double second_sh_idx = Double.parseDouble(secondPresentMap.get("second_sh_idx"));
double second_sz_idx = Double.parseDouble(secondPresentMap.get("second_sz_idx"));
double second_cyb_idx = Double.parseDouble(secondPresentMap.get("second_cyb_idx"));
String per_sh_idx = String.format("%.2f", (sh_idx-second_sh_idx)*100/second_sh_idx);
String per_sz_idx = String.format("%.2f", (sz_idx-second_sz_idx)*100/second_sz_idx);
String per_scyb_idx = String.format("%.2f", (cyb_idx-second_cyb_idx)*100/second_cyb_idx);
double sh_amt = Double.parseDouble(map.ge