https://blog.csdn.net/Tracycater/article/details/73441010

引入Maven依赖包

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
1
2
3
4
163邮箱

application.properties

#####163邮箱########
spring.mail.host=smtp.163.com
spring.mail.username=*****@163.com
#163邮箱密码
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
1
2
3
4
5
6
7
8
运行类:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes=Application.class)
public class My163MailTest {

@Autowired
private JavaMailSender javaMailSender;

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

@Test
public void testSendSimple() {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(username);
message.setTo("*******@qq.com");
message.setSubject("标题:测试标题");
message.setText("测试内容部份");
javaMailSender.send(message);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
QQ邮箱和163邮箱的区别是需要设置授权码而不是密码,具体操作参考:
http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256

application.properties

######qq邮箱########
spring.mail.host=smtp.qq.com
spring.mail.username=******@qq.com
#QQ邮箱授权码
spring.mail.password=xuojxtkdojvzbhjj
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
1
2
3
4
5
6
7
8
运行类:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes=Application.class)
public class MyQQMailTest {

@Autowired
private JavaMailSender javaMailSender;

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

@Test
public void testSendSimple() {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(username);
message.setTo("******@qq.com");
message.setSubject("标题:测试标题");
message.setText("测试内容部份");
javaMailSender.send(message);
}
}
---------------------
作者:罗罗诺亚-小鱼
来源:CSDN
原文:https://blog.csdn.net/Tracycater/article/details/73441010
版权声明:本文为博主原创文章,转载请附上博文链接!

JavaMailSender怎么发送163和qq邮件的更多相关文章

  1. 使用python发送163邮件 qq邮箱

    使用python发送163邮件 def send_email(title, content): import smtplib from email.mime.multipart import MIME ...

  2. spring boot:发送带附件的邮件和html内容的邮件(以163.com邮箱为例/spring boot 2.3.2)

    一,网站哪些情况下需要发送电子邮件? 作为一个电商网站,以下情况需要发邮件通知用户: 注册成功的信息 用邮箱接收验证码 找回密码时发链接 发送推广邮件 下单成功后的订单通知 给商户的对账单邮件 说明: ...

  3. 5分钟 wamp下php phpmaile发送qq邮件 2015最新方法说明

    13:40 2015/11/20 5分钟 wamp下php phpmaile发送qq邮件 2015最新方法说明 关键点:现在qq邮箱开通smtp服务后会给你一个很长的独立新密码,发邮件配置中的密码需要 ...

  4. java代码如何发送QQ邮件

    近来想写一个qq之间互相发送邮件的工具.奈何一直报错服务错误: org.apache.commons.mail.EmailException: Sending the email to the fol ...

  5. 利用Python+163邮箱授权码发送带附件的邮件

    背景 前段时间写了个自动爬虫的脚本,定时在阿里云服务器上执行,会从某个网站上爬取链接保存到txt文本中,但是脚本不够完善,我需要爬虫完毕之后通过邮件把附件给我发送过来,之前写过一个<利用Pyth ...

  6. flask_mail发送163邮件,报553错误的原因

    最近在练习用flask_mail发送163邮件时报错: reply: '553 authentication is required,163 smtp9,DcCowAD3eEQZ561caRiaBA- ...

  7. 【python】脚本连续发送QQ邮件

    今天习得用python写一个连续发送QQ邮件的脚本,经过测试,成功给国内外的服务器发送邮件,包括QQ邮箱.163邮箱.google邮箱,香港科技大学的邮箱和爱丁堡大学的邮箱.一下逐步解答相关技巧. 首 ...

  8. C#发送QQ邮件

    1.首先配置一下发件人的账号密码(密码根据自己所选择的的邮箱填写,此处不做展示) <?xml version="1.0" encoding="utf-8" ...

  9. python 发送QQ邮件的小例子

    首先QQ邮件用第三方客户端发送要申请验证码.而不是QQ的密码. 授权码就是你接下来登录要使用的密码 那么剩下的工作就很简单了.附简单代码如下: #coding:utf-8 import smtplib ...

随机推荐

  1. 纯js实现省市级联效果

    我们都知道一般有注册的时候会让用户填入省市啊地区什么的,然后我就想使用纯js制作一个省市级联的效果,只是用于学习以及回顾温习用,首先看下效果图,界面很丑啊,不要嫌弃! 首先还是先看下我的项目目录吧 很 ...

  2. SSH框架中hibernate 出现 user is not mapped 问题

    SSH框架中hibernate 出现 user is not mapped 问题      在做SSH框架整合时,在进行DAO操作时.这里就只调用了chekUser()方法.运行时报  user is ...

  3. ubuntu16.04 跑Apollo Demo

    1.安装docker(参考网址:https://docs.docker.com/install/linux/docker-ce/ubuntu/) Uninstall old versions Olde ...

  4. ARM、DSP、FPGA的技术特点和区别

    在嵌入式开发领域,ARM是一款非常受欢迎的微处理器,其市场覆盖率极高,DSP和FPGA则是作为嵌入式开发的协处理器,协助微处理器更好的实现产品功能. 那三者的技术特点以及区别是什么呢?下文就此问题略做 ...

  5. CS231n 2016 通关 第五、六章 Batch Normalization 作业

    BN层在实际中应用广泛. 上一次总结了使得训练变得简单的方法,比如SGD+momentum RMSProp Adam,BN是另外的方法. cell 1 依旧是初始化设置 cell 2 读取cifar- ...

  6. Sherlock and the Encrypted Data

    题意: 对于16进制数字num,假定 $p_0,p_1,...,p_m$ 在该数字中出现过,如果有 $x = 2^{p_0} + 2^{p_1} + ... + 2^{p_m}$ 且 $x \oplu ...

  7. Android 电脑投屏工具Vysor Pro介绍

    Chrome的插件,直接到chrome的扩展程序里面搜索Vysor,安装即可 如何破解: C:\Users\lanlan.shi\AppData\Local\Google\Chrome\User Da ...

  8. D3.js(v3)+react 制作 一个带坐标轴与比例尺的折线图

    本章使用路径生成器来绘制一个折线图.以中国和日本的GDP数据为例:   //数据 var dataList = [ { coountry : "china", gdp : [ [2 ...

  9. Lightoj1011【KM算法】

    题意: 问男孩女孩最大的可能值?其实就是一个二分图的最大权值匹配问题:模板题吧.. #include<cstdio> #include<math.h> #include< ...

  10. thinkphp5.0 页面缓存

    在application\config.php里加 //以下为静态缓存配置 'app_debug' => false,//false为开启静态缓存模式 'html_cache_on' => ...