springcloud 整合email的坑(Unrecognized SSL message, plaintext connection?)
springcloud整合email真的是搞得我脑壳痛,因为我需要注册的时候通过rabbitmq给用户发一封邮件,因为这个报错的原因导致我mq一直监听失败然后就开始了循环发消息,这就导致邮箱一直在不停的发。
话不多说直接给解决方案。
需要的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--email配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
email服务邮箱的yml
其中 protocol: smtp的配置查了好多博客,一些说使用465需要smtps,经过我的测试好像都可以没什么区别
spring:
# 邮箱配置
mail:
# 配置 SMTP 服务器地址
host: smtp.qq.com
# 发送者邮箱
username: xxxxxxx@qq.com
# 配置密码,注意这不是真正的密码,而是刚刚申请到的16位授权码
password: nxarhendrqmlbddd
# 端口号465或587
port: 465
# 默认的邮件编码为UTF-8
default-encoding: UTF-8
#这里完全可以直接用smtp
protocol: smtp
test-connection: false
properties:
mail:
debug: true
smtp:
ssl:
enable: true
auth: true
socketFactory:
#这个可要可不要
# class: javax.net.ssl.SSLSocketFactory
port: 465
starttls:
enable: true
required: true
邮件发送
import com.cn.me.result.CommonResult;
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.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
/**
* @author Dshzs月
* @version 1.0.0
* @ClassName SendEmailController.java
* @Description TODO
* @createTime 2022年03月24日 10:36:00
*/
@RestController
public class SendEmailController {
@Autowired
private JavaMailSender javaMailSender;
@Value("${spring.mail.username}")
private String name;
// 上传文件存储目录
@RequestMapping("/email")
public void email(@RequestParam("email") String email,@RequestParam("title") String title,@RequestParam("content") String content) {
// 构建一个邮件对象
SimpleMailMessage message = new SimpleMailMessage();
// 设置邮件主题
message.setSubject(title);
// 设置邮件发送者,这个跟application.yml中设置的要一致
message.setFrom(name);
// 设置邮件接收者,可以有多个接收者,中间用逗号隔开,以下类似
// message.setTo("10*****16@qq.com","12****32*qq.com");
message.setTo(email);
// 设置邮件抄送人,可以有多个抄送人
//message.setCc("12****32*qq.com");
// 设置隐秘抄送人,可以有多个
//message.setBcc("7******9@qq.com");
// 设置邮件发送日期
message.setSentDate(new Date());
// 设置邮件的正文
message.setText(content);
// 发送邮件
javaMailSender.send(message);
}
}
应为我是通过feign调用那么也贴一些feign
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author Dshzs月
* @version 1.0.0
* @ClassName SendEmailFeignClient.java
* @Description TODO
* @createTime 2022年03月25日 14:26:00
*/
@FeignClient(value = "email-server")
public interface SendEmailFeignClient {
@RequestMapping(value = "email", consumes = "application/json")
void email(@RequestParam("visitoremail") String email, @RequestParam("title") String title, @RequestParam("content") String content);
}
消费端调用
import com.cn.me.feign.SendEmailFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author Dshzs月
* @version 1.0.0
* @ClassName Tool.java
* @Description TODO
* @createTime 2022年03月25日 14:25:00
*/
@Component
public class Tool {
@Autowired
private SendEmailFeignClient sendEmailFeignClient;
/**
* 发送邮件的方法
*
* @param email
*/
public void sendEmails(String username, String email) {
//定义标题
String title = "欢迎加入我们!";
//定义内容
String content = "您好,您在婚纱殿的账户激活成功,您的登录用户名是: " +username+
",谢谢您的青睐 0^0!";
//通过sendEmailController调用email方法
sendEmailFeignClient.email(email, title, content);
}
mq就不贴了。
总结:导致(Unrecognized SSL message, plaintext connection?)的元凶就是ssl需要开启,协议http和https是不同的,然后端口不能用587
springcloud 整合email的坑(Unrecognized SSL message, plaintext connection?)的更多相关文章
- Azkaban启动web--javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? at sun.se
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? at sun.se javax.net.ssl. ...
- presto——java.sql.SQLException: Error executing query与javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?异常问题
使用presto的时候以mysql为presto的数据源 安装的presto是0.95版本:使用的presto-jdbc是0.202的,这里使用jdbc去访问时候,connection可以链接成功,但 ...
- httpclient信任所有证书解决SSLException:Unrecognized SSL message,plaintext connection
在使用 HttpClient 工具调用第三方 Http 接口时报错 javax.net.ssl.SSLException:Unrecognized SSL message,plaintext conn ...
- javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection
客户端向服务器发送数据时,份两种情况,SSL单向验证和SSL双向验证 1.SSL单向验证时 代码如下: import java.io.IOException; import java.util.Has ...
- Unrecognized SSL message, plaintext connection? 将https 换为http 即可
请求链接:https://59********* 升级后的项目地址有https换为了http ,出现这个错误,改为http请求即可
- Unrecognized SSL message, plaintext connection--SSLSocket 代理服务器连接
虽然java代码 URL.openconnect(proxy);已经实现了https客户端通过代理连接服务器 但个人在使用socket https代理http://www.cnblogs.com/h ...
- 10.整合email
整合email <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...
- 19.SpringCloud实战项目-SpringCloud整合Alibaba-Nacos配置中心
SpringCloud实战项目全套学习教程连载中 PassJava 学习教程 简介 PassJava-Learning项目是PassJava(佳必过)项目的学习教程.对架构.业务.技术要点进行讲解. ...
- SpringCloud实战 | 第五篇:SpringCloud整合OpenFeign实现微服务之间的调用
一. 前言 微服务实战系列是基于开源微服务项目 有来商城youlai-mall 版本升级为背景来开展的,本篇则是讲述SpringCloud整合OpenFeign实现微服务之间的相互调用,有兴趣的朋友可 ...
- SpringCloud实战 | 第四篇:SpringCloud整合Gateway实现API网关
一. 前言 微服务实战系列是基于开源微服务项目 有来商城youlai-mall 版本升级为背景来开展的,本篇则是讲述API网关使用Gateway替代Zuul,有兴趣的朋友可以进去给个star,非常感谢 ...
随机推荐
- [WPF]DataContext结果不显示
namespace DataContext_ItemSource_Demo { public class Person { public string Name; } public class Vie ...
- Linux c 程序自动启动自己
在程序自动升级的时候需要自己重新启动自己 #include <stdio.h> #include <stdlib.h> #include <unistd.h> in ...
- (转载)Python中关键词yield怎么用?
原文: https://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do 译文: https://zhuanlan.z ...
- 浅谈Python中的with,可能有你不知道的
Python中的with,没那么简单,虽然也不难 https://docs.python.org/zh-cn/3.9/reference/compound_stmts.html#the-with-st ...
- Nginx11 openresty连接redis(lua-resty-redis)
1 官网 http://openresty.org/cn/lua-resty-redis-library.html https://github.com/openresty/lua-resty-red ...
- 服务器设置导致mongo数据库的链接数受限
记录一次使用 mongoDB 遇到的BUG,就是服务链接mongodb报错 [05-Nov-2022 16:46:05] WARNING: [pool www] child 10231 said in ...
- Quartz与Topshelf结合实现window定时服务
一,新建控制台应用程序 二,选中项目,右键 - 管理 NuGet 程序包,添加四个: Quartz Quartz.Plugins Topshelf log4net 三,创建项目文件 三个配置文件:必须 ...
- 学习Java Day22
今天学习了如何在包中增加类,想要将包放入类中,就必须将包的名字放在源文件的开头,即放在定义这个包中各个类的代码之前
- vue组件的对象式写法,vue中的h函数
render:将虚拟dom转为真实dom h函数:创建的是vnode,也可以成为createVnode函数 语法:h(元素名称 ,这个元素的数据,子集) 第一个参数:可以为一个html标签,一个组件, ...
- C语言小程序-天天酷跑类游戏 26号完成
1.创建游戏内背景 2.实现人物 奔跑 跳跃 优化帧 3.障碍物 出现 https://kxd.lanzoul.com/iKXU20elmtah 开源地址 半成品