Skip to content

Commit b33d21f

Browse files
author
xuzheng
committed
add qq email sender
1 parent 8669a26 commit b33d21f

File tree

5 files changed

+61
-22
lines changed

5 files changed

+61
-22
lines changed

pom.xml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
<version>1.0-SNAPSHOT</version>
1010
<packaging>jar</packaging>
1111
<name>springbootstudy</name>
12-
<description>my springboot study demo.</description>
12+
<description>my springboot study demo</description>
1313

1414
<!-- Inherit defaults from Spring Boot -->
1515
<parent>
1616
<groupId>org.springframework.boot</groupId>
17-
<artifactId>spring-boot-starter</artifactId>
17+
<artifactId>spring-boot-starter-parent</artifactId>
1818
<version>2.0.5.RELEASE</version>
19+
<relativePath></relativePath>
1920
</parent>
2021

2122
<!-- Add typical dependencies for a web application -->
@@ -87,6 +88,20 @@
8788
<artifactId>spring-boot-maven-plugin</artifactId>
8889
<configuration>
8990
<fork>true</fork>
91+
<mainClass>com.azxx.demon.Starter</mainClass>
92+
</configuration>
93+
</plugin>
94+
<plugin>
95+
<artifactId>maven-compiler-plugin</artifactId>
96+
<version>3.1</version>
97+
<configuration>
98+
<source>1.8</source>
99+
<target>1.8</target>
100+
<encoding>UTF-8</encoding>
101+
<!--<compilerArguments> -->
102+
<!--<bootclasspath>${java.home}\lib\rt.jar;${java.home}\lib\jce.jar</bootclasspath> -->
103+
<!--<bootclasspath>/data/java/jdk1.8.0_131/lib/rt.jar;/data/java/jdk1.8.0_131/lib/jce.jar</bootclasspath> -->
104+
<!--</compilerArguments> -->
90105
</configuration>
91106
</plugin>
92107
</plugins>

src/main/java/com/azxx/demon/schedule/WeatherJob.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public void queryWeather(){
4242
}
4343

4444
@Scheduled(cron = "0 0 0,6,7,8,12,17,22 * * ? ")
45+
// @Scheduled(cron = "0/20 * * * * *")
4546
public void queryHeWeather(){
4647
String response = HttpUtils.httpGet(url,null);
4748
logger.info(response);
@@ -62,12 +63,12 @@ public void queryHeWeather(){
6263
tmp = heWeather3;
6364
result += String.format("时间:%s,最高温度:%s,最低温度:%s,天气状况:%s,紫外线强度:%s.\n",tmp.getDate(),tmp.getTmp_max(),tmp.getTmp_min(),tmp.getCond_txt_d(),tmp.getUv_index());
6465
}
65-
emailService.sendSimpleEmail("[email protected]","weather report",result);
66+
emailService.sendSimpleEmail("[email protected]","【天气预报】",result);
6667
logger.info(result);
6768
}
6869

6970
// @Scheduled(cron = "0/5 * * * * *")
7071
public void sendMail(){
71-
emailService.sendSimpleEmail("[email protected]","test","时间:2018-10-10,最高温度:28,最低温度:20,天气状况:阵雨,紫外线强度:4.");
72+
emailService.sendSimpleEmail("[email protected]","【天气预报】","时间:2018-10-10,最高温度:28,最低温度:20,天气状况:阵雨,紫外线强度:4.");
7273
}
7374
}

src/main/java/com/azxx/demon/utils/HttpUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package com.azxx.demon.utils;
22

33
import org.apache.http.HttpEntity;
4-
import org.apache.http.client.HttpClient;
54
import org.apache.http.client.config.RequestConfig;
65
import org.apache.http.client.entity.UrlEncodedFormEntity;
76
import org.apache.http.client.methods.CloseableHttpResponse;
87
import org.apache.http.client.methods.HttpGet;
98
import org.apache.http.client.methods.HttpPost;
10-
import org.apache.http.client.methods.HttpUriRequest;
9+
import org.apache.http.client.utils.URIBuilder;
1110
import org.apache.http.impl.client.CloseableHttpClient;
1211
import org.apache.http.impl.client.HttpClients;
1312
import org.apache.http.message.BasicNameValuePair;
@@ -16,6 +15,7 @@
1615
import org.slf4j.LoggerFactory;
1716

1817
import java.io.IOException;
18+
import java.net.URI;
1919
import java.util.ArrayList;
2020
import java.util.List;
2121
import java.util.Map;
@@ -26,18 +26,19 @@ public class HttpUtils {
2626

2727
public static String httpGet(String url, Map<String, String> params) {
2828

29+
// URI uri = new URIBuilder().setScheme("http").setHost("").setPath("").setParameter("name", "xuzheng").build();
2930
StringBuffer sb = new StringBuffer();
3031
if (params != null) {
3132
for (Map.Entry<String, String> entry : params.entrySet()) {
3233
String param = entry.getKey() + "=" + entry.getValue();
3334
sb.append(param + "&");
3435
}
35-
url = url+"?"+sb.toString();
36+
url = url + "?" + sb.toString();
3637
}
3738
//1.创建HttpClient
3839
CloseableHttpClient client = HttpClients.createDefault();
3940
//2.创建HttpGet
40-
HttpGet httpGet = new HttpGet(url );
41+
HttpGet httpGet = new HttpGet(url);
4142
CloseableHttpResponse response = null;
4243
String content = null;
4344

src/main/resources/application-dev.yml

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,43 @@ weather:
66
# url: http://api.help.bj.cn/apis/weather6d/?id=101280601
77
url: https://free-api.heweather.com/s6/weather/forecast?location=%E6%B7%B1%E5%9C%B3&key=be429c34e84e48f19e41f6072f7563a3
88

9+
# outlook 邮箱配置
10+
#spring:
11+
#
12+
# mail:
13+
# host : smtp.office365.com
14+
# port : 587
15+
# username : [email protected]
16+
# password : shouwang-13
17+
# properties:
18+
# mail:
19+
# smtp:
20+
# auth : true
21+
# timeout : 25000
22+
# socketFactory :
23+
# fallback : true
24+
# starttls:
25+
# enable : true
26+
# required : true
27+
28+
# QQ邮箱配置
929
spring:
1030

1131
mail:
12-
host : smtp.office365.com
13-
port : 587
14-
username : mr.xuzheng@outlook.com
15-
password : shouwang-13
32+
host : smtp.qq.com
33+
# port : 465
34+
username : mr.xuzheng@foxmail.com
35+
password : mdcbwhtrugjkbjaf
1636
properties:
17-
mail:
18-
smtp:
19-
auth : true
20-
timeout : 25000
21-
socketFactory :
22-
fallback : true
23-
starttls:
24-
enable : true
25-
required : true
37+
mail:
38+
smtp:
39+
auth : true
40+
timeout : 25000
41+
socketFactory :
42+
fallback : true
43+
starttls:
44+
enable : true
45+
required : true
2646

2747
email :
28-
emailFrom : mr.xuzheng@outlook.com
48+
emailFrom : mr.xuzheng@foxmail.com

src/test/java/com/azxx/demon/utils/HttpUtilsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import com.azxx.demon.modal.HeWeather;
44
import com.azxx.demon.modal.TodayWeather;
55
import com.google.gson.*;
6+
import org.junit.Ignore;
67
import org.junit.Test;
78

89
import java.util.ArrayList;
910
import java.util.List;
1011

1112

13+
@Ignore
1214
public class HttpUtilsTest {
1315

1416
@Test

0 commit comments

Comments
 (0)