一、导入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. 【PHP】五分钟教你编写一个实时弹幕网站

    由于博主是个忠实的英雄联盟粉丝,所以经常观看一些明星大神的直播.而一谈到直播,肯定会看到满屏幕飘来飘去的弹幕.那么问题来了,这些视频弹幕网站如何做到实时同步的?PHP如何开发一个类似的网站? 首先要搞 ...

  2. Delphi 常用语句

    1.屏蔽Float浮点数出错: Set8087CW(Longword($133f)); 2.Idhttp参数设置: FIdhttp                  := TIdHTTP.Create ...

  3. (转)C# WebApi 接口返回值不困惑:返回值类型详解

    原文地址:http://www.cnblogs.com/landeanfen/p/5501487.html 正文 前言:已经有一个月没写点什么了,感觉心里空落落的.今天再来篇干货,想要学习Webapi ...

  4. luogu Eat the Trees

    /* 用和模板类似的方法就行 但是实际上弱化版不用考虑匹配情况限制更加宽松, 只需要保存每个位置有无插头即可, */ #include<cstdio> #include<algori ...

  5. Tomcat启动报错:Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies

    错误代码如下: Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for ...

  6. 在html中使用thymeleaf编写通用模块

    在编写页面时,常常会需要用到通用模块,比如header部分.footer部分等. 项目前端使用的是themeleaf模板引擎,下面简单介绍下使用themeleaf写header通用模块: 1. 通用部 ...

  7. Centos下添加用户并赋权

    创建新用户 创建一个用户名为:linuxidc [root@localhost ~]# adduser linuxidc 为这个用户初始化密码,linux会判断密码复杂度,不过可以强行忽略: [roo ...

  8. android开发 写一个自定义形状的按键

    步骤: 1.在drawable 文件夹中创建一个xml布局文件. 2.修改布局文件 3.在需要使用背景的按键中导入布局. 创建布局文件: 修改布局文件: <?xml version=" ...

  9. [转] 高频 mos 选择需要考虑相关资料

    节选自 http://www.dianyuan.com/bbs/987183.html [草根大侠]贴 关于MOS管导通内阻和米勒电容(Qgd)差异对效率的影响 http://www.epc.com. ...

  10. python pyqt面板切换