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. 用css截取字符 css排版隐藏溢出文本

    方法一: <div style="width:300px; overflow:hidden;  text-overflow:ellipsis; white-space:nowrap;& ...

  2. JQ对象和原生DOM对象

    相同点:两者本质上都是DOM元素. 不同点:JQ对象是在原生DOM对象上进行了一次封装,使开发人员使用起来更简洁.高效. 两者之间用法也完全不同,很说初学者经常混淆. 其实区分两者并不难, 1.语法不 ...

  3. bzoj 3781 小B的询问——分块

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3781 非常经典的分块套路.于是时间空间比大家的莫队差了好多…… #include<io ...

  4. mtk lk阶段的lcm流程

    一.lk进入kmain() 1. vendor/mediatek/proprietary/bootable/bootloader/lk/arch/arm/srt0.S bl kmain 二.初始化lk ...

  5. SpringMVC注解说明

    @controller 通过@controller标注即可将class定义为一个controller类. @RequestMapping value 表示需要匹配的url的格式. method 表示所 ...

  6. 【223】◀▶ IDL HDF 文件操作说明

    参考:I/O - HDF Routines —— HDF 操作函数 01   HDF_SD_START 打开一个 SDS 模式的 HDF 文件. 02   HDF_SD_END 关闭一个 SDS 模式 ...

  7. Httpclient爬取优酷网

    参考:http://www.cnblogs.com/lchzls/p/6277210.html /httpClient/src/main/java/com/louis/youku/Page.java ...

  8. SSE2介绍及其简单用法举例

    http://blog.csdn.net/fengbingchun/article/details/18515241

  9. 2、css的存在形式及优先级

    一.优先级 简单可以理解为就近原则: <html lang="en"> <head> <meta charset="UTF-8"& ...

  10. linux中的调试知识---基础gdb和strace查看系统调用信息,top性能分析,ps进程查看,内存分析工具

    1 调试一般分为两种,可以通过在程序中插入打印语句.有点能够显示程序的动态过程,比较容易的检查出源程序中的有关信息.缺点就是效率比较低了,而且需要输入大量无关的数据. 2 借助相关的调试工具. 3 有 ...