springboot2.x中的服务监控之邮件预警

上一篇文章写了怎么在springboot2.x中添加服务监控,如果有需要的小伙伴可以回头看一眼,《springboot2.x中的服务监控》,可是这还需要我时不时的来登录一下系统查看一下,好麻烦,要是能有提醒就好了。当然我们想到的人家spring的大神早已想到,本来就来解决这个“不方便”

先来看个最终效果

《springboot2.x中的服务监控之邮件预警》 提醒邮件.png

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

《springboot2.x中的服务监控之邮件预警》 POP3/SMTP.png

链接【戳我获取源码】

    原文作者:小尘哥
    原文地址: https://www.jianshu.com/p/e66cb7c2b1cc
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞