使用SpringBoot 发送简单邮件

1. 在pom.xml中导入依赖

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

2. 配置application.properties文件

在此我们以QQ邮箱为例, 秘钥使用的是QQ邮箱POP3/SMTP服务提供的秘钥并不是登录密码

#发送邮件配置
spring.mail.host=smtp.qq.com
spring.mail.username=QQ号码(邮件发送方)
spring.mail.password=秘钥
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true

3. 写一个测试类

import javafx.application.Application;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = YisizhusystemApplication.class)
public class ApplicationTests { @Autowired
private JavaMailSender mailSender; @Test
public void sendSimpleMail() throws Exception {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("发送方@qq.com");
message.setTo("接收方@163.com");
message.setSubject("主题:简单邮件");
message.setText("测试邮件内容"); mailSender.send(message);
} }

QQ邮箱授权码获取方法

SpringBoot 发送简单邮件的更多相关文章

  1. 使用SpringBoot发送mail邮件

    1.前言 发送邮件应该是网站的必备拓展功能之一,注册验证,忘记密码或者是给用户发送营销信息.正常我们会用JavaMail相关api来写发送邮件的相关代码,但现在springboot提供了一套更简易使用 ...

  2. JavaMail发送简单邮件

    非常简单的发送邮件实现,网上有很多啦,但还是自己写写记录下吧. package cn.jmail.test; import java.util.Properties; import javax.mai ...

  3. 关于使用 Spring 发送简单邮件

    这是通过Spring 框架内置的功能完成简单邮件发送的测试用例. 导入相关的 jar 包. Spring 邮件抽象层的主要包为 org.springframework.mail. 它包括了发送电子邮件 ...

  4. 使用javaMail发送简单邮件

    参考网页:http://blog.csdn.net/xietansheng/article/details/51673073package com.bfd.ftp.utils; import java ...

  5. (一)JavaMail发送简单邮件

    1,导入依赖 <dependency> <groupId>com.sun.mail</groupId> <artifactId>jakarta.mail ...

  6. SpringBoot发送简单文本邮件

    1.pom.xml添加 spring-boot-starter-mail 依赖 <dependency> <groupId>org.springframework.boot&l ...

  7. Java Mail发送简单邮件,完整代码

    依赖javax.mail.jar,地址:https://java.net/projects/javamail/pages/Home 完整示例代码如下: package com.jadic.utils; ...

  8. Python通过yagmail和smtplib模块发送简单邮件

    SMTP是发送邮件的协议,Python内置对SMTP的支持,可以发送纯文本邮件.HTML邮件以及带附件的邮件.python发邮件需要掌握两个模块的用法,smtplib和email,这俩模块是pytho ...

  9. springboot发送email邮件

    添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>sp ...

随机推荐

  1. LG2766 最长不下降子序列问题 最大流 网络流24题

    问题描述 LG2766 题解 \(\mathrm{Subtask 1}\) 一个求最长不下降子序列的问题,发现\(n \le 500\),直接\(O(n^2)\)暴力DP即可. \(\mathrm{S ...

  2. 【oracle】ORA-12638 : 身份证明检索失败

    sqlnet.ora 1.删了 2.#注释了 背后缘由:待写

  3. 6-ESP8266 SDK开发基础入门篇--操作系统入门使用

    了解了8266的串口了,这一节咱就自己写程序,处理一下数据,如果接收到 0xaa 0x55 0x01  就控制指示灯亮 0xaa 0x55 0x00  就控制指示灯灭 注意哈,我是用的假设没有操作系统 ...

  4. [RN] React-Native中Array渲染的优化

    React-Native中Array渲染的优化 例如用Push加进去的数据: constructor(props){    super(props);    this.state = {      b ...

  5. 前端Vue项目——课程详情页面实现

    一.详情页面路由跳转 应用 Vue Router 编程式导航通过 this.$router.push() 来实现路由跳转. 1.绑定查看详情事件 修改 src/components/Course/Co ...

  6. [LeetCode] 215. Kth Largest Element in an Array 数组中第k大的数字

    Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...

  7. [LeetCode] 82. Remove Duplicates from Sorted List II 移除有序链表中的重复项之二

    Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...

  8. nodejs的child_process

    child_process  模块提供了衍生子进程的能力 异步方式:spawn.exec.execFile.fork 同步方式:spawnSync.execSync.execFileSync 说明: ...

  9. StackExchange.Redis Timeout performing 超时问题

    最近在做的一个项目,用的.net core 2.1,然后缓存用的Redis,缓存相关封装是同事写的,用的驱动是StackExchange.Redis version 2.0.571 ,一直听说这个驱动 ...

  10. 如何写APA格式的论文

    一.一般准则 FONT :   TIMES NEW ROMAN SIZE                    :   12 DOUBLE-SPACING INDENT               : ...