pom.xml

<!--邮件javax.mail-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>

MyController.class

@Controller
public class MyController {
@Autowired
AsyncService asyncService;
@ResponseBody
@GetMapping("/hello")
public String hello(){
asyncService.hello();
return "你好";
}
}

AsyncService.class

@Service
public class AsyncService {
@Async
public void hello(){
try {
Thread.sleep(3000);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("数据正在处理。。。。。。");
} }

SpringbootTaskApplication.class

@EnableAsync //开启异步注解功能
@SpringBootApplication
public class SpringbootTaskApplication { public static void main(String[] args) {
SpringApplication.run(SpringbootTaskApplication.class, args);
}
}

application.properties

spring.mail.username=110xxxxx@qq.com
#授权码
spring.mail.password=xxxxxxxxxxxxx
spring.mail.host=smtp.qq.com
#开启加密验证
spring.mail.properties.mail.smtp.ssl.enable=true

SpringbootTaskApplicationTest.class

@SpringBootTest
class SpringbootTaskApplicationTests {
@Autowired
JavaMailSenderImpl mailSender;
@Test
void contextLoads() {
SimpleMailMessage message=new SimpleMailMessage();
message.setSubject("xx你好啊");
message.setText("java这条路行下去");
message.setTo("110xxxxx6@qq.com");
message.setFrom("110xxxxx56@qq.com");
mailSender.send(message);
} }

最新文章

  1. Xshell访问虚拟机内Linux
  2. Nam Game
  3. 通过rsync搭建一个远程备份系统(一)
  4. 【转贴】全站 HTTPS 来了
  5. Longest Ordered Subsequence
  6. APK 代码混淆
  7. JAVA 统计字符串中中文,英文,数字,空格的个数
  8. JavaScript绘制表格并将内容以JSON返回后台
  9. 解决Nginx+Tomcat时ContextPath不同的问题
  10. Django+Bootstrap+Mysql 搭建个人博客 (六)
  11. fiddler修改Requests之前的数据和response 之后的数据
  12. [转] 一张图理解prototype、proto和constructor的三角关系
  13. 【MySQL】MySQL查询数据库各表的行数
  14. 基于vue-cli配置手淘的lib-flexible + rem,实现移动端自适应
  15. exe4j使用说明
  16. Appium+python自动化3-定位元素
  17. sys和os模块
  18. 树莓派3 U盘启动 配置 &amp; 即 MSD启动 总结
  19. wmi收集系统信息 发送到服务器打印
  20. SQL Server Job

热门文章

  1. redus - 队列
  2. Docker 版本的更新和安装
  3. numpy中flatten学习笔记
  4. c++ for_each
  5. java+断点续传
  6. JAVA 基础编程练习题29 【程序 29 求矩阵对角线之和】
  7. [Python]编译错误:编码错误问题(SyntaxError: (unicode error) )
  8. Clonezilla克隆还原系统
  9. 【从零开始搭建K8S】【第一篇】CentOS7.6离线安装Docker(手动安装以及基于yum本地源安装)
  10. Bulid过程中中遇到的问题UnityEditor.BuildPlayerWindow+BuildMethodException: &#39;&#39; is an incorrect path for a scene file. BuildPlayer expects paths relative to the project folder.