java发送email

本文介绍了如何利用SpringBoot结合Thymeleaf模板引擎,通过QQ邮箱的授权码来实现邮件的发送。步骤包括获取邮箱授权码、创建SpringBoot Web项目、引入Thymeleaf依赖、配置邮件服务参数、编写HTML邮件模板以及测试发送邮件。
摘要由CSDN通过智能技术生成

如何用Java实现邮件发送?

用springboot+thymeleaf来简单的实现邮件的发送任务。(example:QQ邮箱)

1.登录QQ邮箱,并且拿到授权码。(设置–>账户–>开启服务–>POP3/SMTP–>登录,得到授权码。
2.创建springboot (web)项目 ,在破pom.xml中引入thymeleaf依赖。

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

3.配置application.properties文件

spring.mail.host=smtp.qq.com
spring.mail.protocol=smtp
spring.mail.username=915166712@qq.com
spring.mail.default-encoding=UTF-8
spring.mail.port=465
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.debug=true
spring.mail.password=htnyjnlwjqfnbefi 

创建HTML

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p>欢迎 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值