上一篇文章寫了怎麼在springboot2.x中添加服務監控,如果有需要的小夥伴可以回頭看一眼,《springboot2.x中的服務監控》,可是這還需要我時不時的來登錄一下系統查看一下,好麻煩,要是能有提醒就好了。當然我們想到的人家spring的大神早已想到,本來就來解決這個“不方便”
先來看個最終效果
pom添加郵件依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
添加yml配置
spring:
application:
name: spring-boot-admin-server
mail:
host: smtp.qq.com
username: xxx@qq.com(你自己的郵箱賬號)
password: (對應的授權碼,下面說明怎麼獲取該授權碼)
properties:
mail.debug: false
mail.smtp.auth: true #安全認證(默認是true)
mail.smtp.port: 465
mail.smtp.ssl.enable: true #開啓ssl加密 否則項目啓動時報530error
mail.smtp.ssl.socketFactory: sf
mail.smtp.starttls.enable: true
mail.smtp.starttls.required: true
boot:
admin:
notify:
mail:
to:接收提醒的郵箱
from:發送人郵箱
這樣就夠了,重新測試你的服務,啓動或者服務掛掉的時候郵箱都能收到提醒了。
授權碼獲取
以下以QQ郵箱爲例(163等郵箱都大差不差)
登錄後進入“郵箱設置”–>“帳戶”–》往下拉–》開啓POP3/SMTP
鏈接:【戳我獲取源碼】