在admin监控的时候,我们希望的是如果有某个服务挂了,那么就发一个邮件,告诉我这个服务挂掉了。
1):在pom文件中,加入包依赖:
1
2
3
4
5
6 1<dependency>
2 <groupId>org.springframework.boot</groupId>
3 <artifactId>spring-boot-starter-mail</artifactId>
4</dependency>
5
6
2):在application.properties中加入邮件信息的配置:
1
2
3
4
5
6
7
8
9
10
11
12
13 1spring.mail.host=smtp.qq.com
2spring.mail.username=844645164
3# 这个地方使用的不是邮箱的密码,而是授权码(如何获取QQ邮箱授权码,自行百度)
4spring.mail.password=xxxxxxxxxxx
5spring.mail.properties.mail.smtp.auth=true
6spring.mail.properties.mail.smtp.starttls.enable=true
7spring.mail.properties.mail.smtp.starttls.required=true
8# 收件邮箱
9spring.boot.admin.notify.mail.to=903832439@qq.com
10# 发件邮箱
11spring.boot.admin.notify.mail.from=844645164@qq.com
12
13
至此,admin服务端就在监控服务状态变化的手,就可以发邮件通知了。
这里,如果有服务的状态变成DOWN,那么邮箱844645164@qq.com就会发送一个邮件到903832439@qq.com邮箱,内容如下: