<!-- 邮件end -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<!--freemarker模板引擎-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
# JavaMailSender 邮件发送的配置s
spring.mail.host=smtp.qq.com
spring.mail.username=97248@qq.com
spring.mail.password=klfncwbbhd
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
# JavaMailSender 邮件发送的配置e
@Autowired
private JavaMailSender mailSender; //自动注入的Bean
@Value("${spring.mail.username}")
private String mailFrom; //读取配置文件中的参数
@Value("${spring.mail.password}")
private String password; //读取配置文件中的参数
private String mailTo = "1336956709@qq.com"; // 加载收件人地址
@Autowired
private FreeMarkerConfigurer freeMarkerConfigurer; //自动注入
@RequestMapping(value = "/sendMail", method = RequestMethod.GET)
public void sendMail() { // 测试 MimeMessage message = null;
try {
message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom(mailFrom);
helper.setTo(mailTo);
helper.setSubject("主题:额度发放");
Map<String, Object> model = new HashMap<>();
model.put("resTypeName", "服务资源");
model.put("resName", "小车00001");
model.put("quota", "10000");
//读取 html 模板
Template template = freeMarkerConfigurer.getConfiguration().getTemplate("mailtemplats/sendQuota.ftl");
String html = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
helper.setText(html, true);
System.out.println("发送成功");
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.toString());
System.out.println("发送失败");
}
mailSender.send(message);
// 测试
}

springboot 邮件的更多相关文章

  1. SpringBoot邮件报警

    SpringBoot邮件报警 一.介绍 邮件报警,大体思路就是收集服务器发生的异常发送到邮箱,做到服务器出问题第一时间知道,当然要是不关注邮箱当我没说 二.配置邮箱 (1).注册两个邮箱账号(一个用来 ...

  2. SpringBoot邮件发送

    这篇文章介绍springboot的邮件发送. 由于很简单就没有分出server和imp之类,只是在controller简单写个方法进行测试. 首先pom文件加入spring-boot-starter- ...

  3. (转)Springboot邮件服务

    springboot仍然在狂速发展,才五个多月没有关注,现在看官网已经到1.5.3.RELEASE版本了.准备慢慢在写写springboot相关的文章,本篇文章使用springboot最新版本1.5. ...

  4. springboot 邮件服务

    springboot仍然在狂速发展,才五个多月没有关注,现在看官网已经到1.5.3.RELEASE版本了.准备慢慢在写写springboot相关的文章,本篇文章使用springboot最新版本1.5. ...

  5. SpringBoot邮件推送功能

    鞠躬,道歉 抱歉,迟到了近一年的更新,这一年挺忙的,发生了很多事情,就厚脸皮拖更了,抱歉. 现在状态回来了,打算分享下近期学到的东西,这一年期间学到的东西可能会随意更新,其实也就是玩了下C# + un ...

  6. Springboot邮件发送思路分析

    毕业设计里需要邮件发送,所以学习,总的来讲,我考虑以下几点, 代码量少,代码简单.配置少,一看就懂,使用 JavaMail 太麻烦了. 异步执行,添加员工之后会发送入职邮件, 多线程处理,设计里有一个 ...

  7. springboot邮件发送与接收读取

    发送邮件 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>sp ...

  8. 19.springboot邮件服务服务器部署访问不到邮箱服务器解决方案

    1.前言 在Springboot项目的生产环境中,win系统环境下,邮箱服务是可以正常使用的. 当项目部署到阿里云服务器上之后,因为服务器端口采用安全组的方式,25端口访问不到. 在网上查找了一部分资 ...

  9. SpringBoot邮件发送功能

    快速入门 在Spring Boot的工程中的pom.xml中引入spring-boot-starter-mail依赖: <dependency> <groupId>org.sp ...

随机推荐

  1. 【Linux】安装mysql之设置远程访问权限

    最近重装了云主机,又要安装各种东西,其中一个就要设置mysql权限 出于学习方便,我在自己的云主机上安装的是phpstudy集成环境,所以要进入mysql控制台不能直接用“mysql -u root ...

  2. CodeForces 651B

    #include <cstdio> #include <algorithm> using namespace std; int a[1005], n, temp, maxk; ...

  3. 模块之 logging模块 time 模块 random模块 sys模块 pickle模块

    1.如果执行文件不在项目根目录下,需要添加项目根目录到sys.path中2.调用业务逻辑 2.logging模块 程序日志是 什么时间发生了什么事情,以及当时的情况 不是logging的话 记录日志的 ...

  4. HDU1505-City Game(记忆化搜索)

    City Game http://acm.hdu.edu.cn/showproblem.php?pid=1505 Problem Description Bob is a strategy game ...

  5. OWINS是什么(转载)

    OWIN的英文全称是Open Web Interface for .NET. 如果仅从名称上解析,可以得出这样的信息:OWIN是针对.NET平台的开放Web接口. 那Web接口是谁和谁之间的接口呢?是 ...

  6. Redis实现之RDB持久化(二)

    RDB文件结构 在Redis实现之RDB持久化(一)这一章中,我们介绍了Redis服务器保存和载入RDB文件的方法,在这一节,我们将对RDB文件本身进行介绍,并详细说明文件各个部分的结构和意义.图1- ...

  7. 【Candy】cpp

    题目: There are N children standing in a line. Each child is assigned a rating value. You are giving c ...

  8. log4j2用asyncRoot配置异步日志是如何使用disruptor

    用asyncRoot配置对应的对接disruptor类是AsyncLoggerConfigDisruptor,用Log4jContextSelector启动参数配置全局异步的对应的对接disrupto ...

  9. jmeter配置分布式调度:远程启动其他机器实现多台pc一起并发

    原文转自:https://www.cnblogs.com/whitewasher/p/6946207.html Jmeter分布式部署测试-----远程连接多台电脑做压力性能测试 在使用Jmeter进 ...

  10. 基于 <tx> 和 <aop> 命名空间的声明式事务管理

    环境配置 项目使用SSH架构,现在要添加Spring事务管理功能,针对当前环境,只需要添加Spring 2.0 AOP类库即可.添加方法: 点击项目右键->Build Path->Add ...