一、导入jar包

    <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>

二、在application.properties种添加邮箱配置

QQ邮箱需要设置开启smtp服务,具体的请查询一下如何开启,此处省略

spring.mail.host=smtp.qq.com
spring.mail.username=54281****@qq.com
spring.mail.password=tneawbzduhvf****
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true

三、发送邮件类

package com.example.demo.timedtask;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import java.text.SimpleDateFormat;
import java.util.Date; @Component
public class Scheduler2Task {
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); @Autowired
private JavaMailSender mailSender; /*
* @Scheduled(fixedRate = 6000) 上一次开始执行时间点之后6秒再执行
* @Scheduled(fixedDelay = 6000) 上一次执行完毕时间之后6秒再执行
* @Scheduled(initialDelay=1000, fixedRate=6000) 第一次延迟1秒后执行,之后按fixedRate的规则执行
* */
@Scheduled(fixedRate = 6000)/*每隔六秒钟执行一次*/
public void reportCurrentTime() {
System.out.println("现在时间:" + dateFormat.format(new Date()));
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("542813934@qq.com");
message.setTo("542813934@qq.com");
message.setSubject("主题:简单邮件1");
message.setText("测试邮件内容1");
mailSender.send(message);
}
}

SpringBoot配置发送邮件的更多相关文章

  1. 使用 SpringBoot 配置发送邮件功能

    1.使用 SpringBoot 配置发送邮件功能 项目总体结构 用户表设计 SET FOREIGN_KEY_CHECKS=0; CREATE DATABASE sample; USE sample; ...

  2. spring boot 学习(十)SpringBoot配置发送Email

    SpringBoot配置发送Email 引入依赖 在 pom.xml 文件中引入邮件配置: <dependency> <groupId>org.springframework. ...

  3. java springboot+maven发送邮件

    springboot+maven发送邮件 废话不多说直接上代码 1. pom 文件导入jar包 <!--邮件发送--> <dependency> <groupId> ...

  4. SpringBoot配置属性之Server

    SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之N ...

  5. zabbix 配置发送邮件报警

    标签:监控/SQLServer/Windows 概述 本篇文章主要介绍如何配置zabbix借助外部邮件进行发送邮件报警,zabbix通过配置文件调用mailx来进行邮件的发送.在Centos6以上的版 ...

  6. SpringBoot基础系列-SpringBoot配置

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9990680.html SpringBoot基础系列-SpringBoot配置 概述 属性 ...

  7. springboot上传文件 & 不配置虚拟路径访问服务器图片 & springboot配置日期的格式化方式 & Springboot配置日期转换器

    1.    Springboot上传文件 springboot的文件上传不用配置拦截器,其上传方法与SpringMVC一样 @RequestMapping("/uploadPicture&q ...

  8. springboot配置Druid数据源

    springboot配置druid数据源 Author:SimpleWu springboot整合篇 前言 对于数据访问层,无论是Sql还是NoSql,SpringBoot默认采用整合SpringDa ...

  9. springboot配置详解

    springboot配置详解 Author:SimpleWu properteis文件属性参考大全 springboot默认加载配置 SpringBoot使用两种全局的配置文件,全局配置文件可以对一些 ...

随机推荐

  1. Java-Runoob-高级教程-实例-方法:10. Java 实例 – 标签(Label)

    ylbtech-Java-Runoob-高级教程-实例-方法:10. Java 实例 – 标签(Label) 1.返回顶部 1. Java 实例 - 标签(Label)  Java 实例 Java 中 ...

  2. mysql默认8小时连接断开机制解决

    转载连接:http://www.myexception.cn/database/1639209.html 本文提供了对c3p0与DBCP连接池连接MySql数据库时, 8小时内无请求自动断开连接的解决 ...

  3. tesseract 中文二次训练

    tesseract4.0以上版本可参考 https://github.com/tesseract-ocr/tesseract/wiki/TrainingTesseract-4.00#tutorial- ...

  4. [UE4]射击起点、终点的计算方法

    一.射击起点,这个简单,一般是以角色的相机位置为作为射击起点,而不是枪口的位置作为起点 二.射击终点,角色朝向 * 射击距离 + 射击起点 角色朝向:单位向量 角色朝向 * 射击距离:向量长度 向量长 ...

  5. echarts3更新

    dataRange: { realtime: false, itemHeight: 80, splitNumber:6, borderWidth:1, textStyle: { color: '#33 ...

  6. python程序化交易神器——tushare

    一直想试着将自己的交易思路程序化,可惜困难重重 ,连第一步获取数据都要花很多精力,直到最近发现了Tushare,不仅使用非常便利,功能也无比强大,股票.期货.基金.财经新闻,甚至电影票房等都可以非常便 ...

  7. CentOS之RPM

    yum工具比RPM工具好用,所以直接介绍yum工具来管理RPM包. yum list |head -n 20 列出所有RPM资源. yum search vim  搜索RPM包vim yum inst ...

  8. Kaptcha

    Kaptcha:google自动生成验证码组件 kaptcha的使用比较方便,只需添加jar包依赖之后简单地配置就可以使用了 kaptcha所有配置都可以通过web.xml来完成,如果你的项目中使用了 ...

  9. kafka的API操作

    在集群的接收端 启动producer 在consumer这边能接收到producer发来的数据

  10. 自然语言处理领域重要论文&资源全索引

    自然语言处理(NLP)是人工智能研究中极具挑战的一个分支.随着深度学习等技术的引入,NLP领域正在以前所未有的速度向前发展.但对于初学者来说,这一领域目前有哪些研究和资源是必读的?最近,Kyubyon ...