springboot-email 邮件发送实战
来源:互联网 发布:淘宝停留时间怎么看 编辑:程序博客网 时间:2024/06/05 07:22
- 开启smtp服务
- 开发环境
邮件发送是项目中经常要用到的功能,我们快速的学习和使用它。
准备工作:
(这里用QQ账号来做测试)
1.开启smtp服务
进入qq邮件后,点击账户,然后点击开启smtp服务,按照步骤开启完成
2.开发环境
- jdk7
- eclipse
使用eclipse创建简单的maven项目,引入springboot配置
项目包结构如下:
配置文件
server.port=8080server.context-path=/emailspring.mail.debug=truespring.mail.host=smtp.qq.comspring.mail.username=492782442@qq.comspring.mail.password=your auth codespring.mail.properties.mail.smtp.auth=truespring.mail.properties.mail.smtp.starttls.enable=truespring.mail.properties.mail.smtp.starttls.required=true
spring.mail.password 密码qq对应得是授权码,如下图获取
核心代码
public String sendSimpleMail() throws Exception { try { SimpleMailMessage message = new SimpleMailMessage(); message.setFrom("492782442@qq.com"); message.setTo("1497187976@qq.com"); message.setSubject("主题:励志程序员"); message.setText("一分钟掌握邮件发送"); mailSender.send(message);} catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); logger.error("发送失败:" + e.getMessage()); return "send error:" + e.getMessage();} return "send success"; }
收信结果:
献上git地址, https://github.com/1497187976/springboot-email.git
不会使用github的移步
人人都要会的github从入门到实战
阅读全文
0 1
- springboot-email 邮件发送实战
- Email邮件发送程序
- Send Email 发送邮件
- java发送Email邮件
- .NET 发送EMAIL邮件
- C#发送Email邮件
- Spring+Email 发送邮件
- commons-email 发送邮件
- email linux 发送邮件
- JAVA发送Email邮件
- php发送邮件email
- C#发送邮件Email
- Java发送email邮件
- php发送邮件email
- php发送邮件email
- php发送邮件email
- php发送邮件email
- php发送邮件email
- 思维搜索骚操作小记
- TMS320F28335学习笔记-启动过程
- 适配器模式
- HTML5权威指南笔记:21-创建布局
- linux 驱动学习之kmalloc 内存分配
- springboot-email 邮件发送实战
- 28-友元
- 线程之间共享数据
- HDU 2020 绝对值排序
- [ElasticSearch]数据类型keyword和text的区别
- python 数据分析 numpy基础
- 创建 CentOS7容器 需要注意的地方
- C 函数指针与回调函数
- 欢迎使用CSDN-markdown编辑器