1. 建项目

    1. 创建一个SpringBoot项目
  2. 改pom,导入相关依赖



    org.springframework.boot

    spring-boot-starter-parent

    2.2.2.RELEASE

    <dependencies>
    <!--web依赖-->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!--邮件发送依赖-->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    </dependency>
    </dependencies>
  3. 写Yml,配置application.yml

    server:

    port: 端口号

    spring:

    mail:

    #邮件发送配置

    default-encoding: UTF-8

    host: smtp.qq.com

    # 授权码

    password: 你的授权码

    # 邮件发送安全配置

    properties:

    mail:

    smtp:

    auth: true

    starttls:

    enable: true

    required: true

    # 发件人信息

    username: 发件人邮箱

  4. 主启动类EmailSignupApplication

    /**

    • @author QiuQiu&LL
    • @create 2021-08-09 2:18
    • @Description:

      */

      @SpringBootApplication

      @ComponentScan("com.qbb")

      public class EmailSignupApplication {

      public static void main(String[] args) {

      SpringApplication.run(EmailSignupApplication.class, args);

      }

      }
  5. 业务

    1. 创建Service

    /**

    • @author QiuQiu&LL
    • @create 2021-08-09 2:18
    • @Description:

      /

      public interface MailService {

      /
      *

      • 发送邮件
      • @param to 邮件收件人
      • @param subject 邮件主题
      • @param verifyCode 邮件验证码

        */

        public void sendVertifyCode(String to, String subject, String verifyCode);

        }
    1. 实现类ServiceImpl

    package com.qbb.email_signup.service.impl;

    import com.qbb.email_signup.service.MailService;

    import org.slf4j.Logger;

    import org.slf4j.LoggerFactory;

    import org.springframework.beans.factory.annotation.Autowired;

    import org.springframework.beans.factory.annotation.Value;

    import org.springframework.mail.SimpleMailMessage;

    import org.springframework.mail.javamail.JavaMailSender;

    import org.springframework.stereotype.Service;

    /**

    • @author QiuQiu&LL

    • @create 2021-08-09 2:20

    • @Description:

      */

      @Service

      public class MailServiceImpl implements MailService {

      @Value("${spring.mail.username}")

      private String from;

      @Autowired

      private JavaMailSender mailSender;

      Logger logger = LoggerFactory.getLogger(this.getClass());

      /**

      • 发送邮件
      • @param to 邮件收件人
      • @param subject 邮件主题
      • @param verifyCode 邮件验证码

        */

        @Override

        public void sendVertifyCode(String to, String subject, String verifyCode) {

        SimpleMailMessage message = new SimpleMailMessage();

        message.setFrom(from); //发送人

        message.setTo(to); //收件人

        message.setSubject(subject); //邮件名

        message.setText(verifyCode); //邮件内容(验证码)

        mailSender.send(message);

        logger.info("已经发送");

        }

        }
  6. 测试

    package com.qbb.email_signup;

    import com.qbb.email_signup.service.MailService;

    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.test.context.junit4.SpringRunner;

    /**

    • @author QiuQiu&LL

    • @create 2021-08-09 2:28

    • @Description:

      */

      @RunWith(SpringRunner.class)

      @SpringBootTest(classes = EmailSignupApplication.class)

      public class MailServiceTest {

      @Autowired

      private MailService mailService;

      @Test

      public void Test1() {

      /填你的测试信息/

      String to = "收件人邮箱";

      String title = "测试邮件";

      String context = "测试验证码";

      mailService.sendVertifyCode(to, title, context);

      }

    }

  7. 结果

SpringBoot实现QQ邮件发送的更多相关文章

  1. 线程——QQ邮件发送

    一.造一个QQ邮件发送的窗体 二.开始编写关于邮件发送的代码,以及当点发送按钮的时候,给发送按钮单独造了一个新的线程.这样如果发送的附件太多的话,如果不给发送按钮造新的线程,便会卡住,但是如果给发送按 ...

  2. Java网络编程:QQ邮件发送客户端程序设计

    目录 一.目标介绍 1.认识SMTP(邮件传输协议) 2.POP3(邮件接收协议) 二.基于Base64编码邮箱及授权码 1.开通QQ邮箱SMTP/POP3服务 2.Java编写BASE64编码程序 ...

  3. Java实现QQ邮件发送客户端

    目录 一.前言:QQ邮件发送程序 二.封装SMTP操作 三.实现多线程接收 四.QQ邮件客户端界面设计 1.连接按钮 2.发送按钮 五.QQ邮件发送效果演示 六.总结 一.前言:QQ邮件发送程序 在上 ...

  4. Springboot+Javamail实现邮件发送

    Springboot+Javamail实现邮件发送 使用的是spring-context-support-5.2.6.RELEASE.jar里的javamail javamail 官方文档:javam ...

  5. python定时利用QQ邮件发送天气预报

    大致介绍 好久没有写博客了,正好今天有时间把前几天写的利用python定时发送QQ邮件记录一下 1.首先利用request库去请求数据,天气预报使用的是和风天气的API(www.heweather.c ...

  6. Java实现QQ邮件发送

    首先我们需要两个jar包,点击下面即可下载这两个包: JavaMail mail.jar 1.4.5 JAF(版本 1.1.1) activation.jar 我们这里采用QQ邮箱发送邮件为例,代码如 ...

  7. 使用Springboot Email实现邮件发送

    在springboot配置文件增加emai配置(此种方式不支持QQ邮箱): spring.datasource.type=com.alibaba.druid.pool.DruidDataSource ...

  8. springboot下实现邮件发送功能

    springboot给我们封装好了邮件功能,非常简单,只需要稍微配置下就ok. 引入jar <dependency> <groupId>org.springframework. ...

  9. springBoot中的邮件发送

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

随机推荐

  1. JAVA-JDK1.8-ConCurrentHashMap-源码并且debug说明

    概述 在上述的随笔中已经介绍了JDK1.7版本的ConCurrentHashMap源码和测试了,现在这篇随笔主要介绍JDK1.8版本的ConCurrentHashMap,这个版本抛弃了分段锁的实现,直 ...

  2. WebGL 与 WebGPU 比对[1] 前奏

    目录 1 为什么是 WebGPU 而不是 WebGL 3.0 显卡驱动 图形 API 的简单年表 WebGL 能运行在各个浏览器的原因 WebGPU 的名称由来 2 与 WebGL 比较编码风格 Op ...

  3. 《剑指offer》面试题32 - II. 从上到下打印二叉树 II

    问题描述 从上到下按层打印二叉树,同一层的节点按从左到右的顺序打印,每一层打印到一行. 例如: 给定二叉树: [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 ...

  4. DataTable 中文国际化

    DataTable中文设置,详见代码 1 var table = $('#example').DataTable({ 2 "language": { 3 "process ...

  5. 记一次redis 基于spring实现类对同一个KEY序列化内容不同导致一次事故

    我们的场景是这样的 我们对一个key:比如list.point.card:1 @Resourceprivate RedisTemplate<String, Long> redisTempl ...

  6. Core 3.1 MVC 抛异常“InvalidOperationException: No service for type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory' has been registered.”

    .NET Core 的版本是 3.1遇到的问题是 Action 中 return View() 的时候报错 An unhandled exception occurred while processi ...

  7. python 小兵(10)内置函数

    内置函数(下午讲解) 什么是内置函数?就是python帮我们提供的一个工具,拿过直接用就行,比如我们的print,input,type,id等等.截止到python3.6.2版本 中一共提供了68个内 ...

  8. C++学习Day 1

    c++的函数需要声明才能再写他的定义,声明可以写多次,如果执行在main之前可以不写,全写不会犯错,现在看好像c++的函数定义里没有out,也没有变量的public和private(后面有再改) 声明 ...

  9. undefined index: php中提示Undefined ...

    我们经常接收表单POST过来的数据时报Undefined index错误,如下:$act=$_POST['action'];用以上代码总是提示Notice: Undefined index: act ...

  10. CSS3带你实现3D转换效果

    前言 在css3中允许使用3D转换来对元素进行格式化,在原本只是2D转化的平面中引入了Z轴.在这之前我们讲解了css3中的2D转换,也就是二维空间变换,本篇的3D转换就是基于原来的2D转换而来,与2D ...