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?)的更多相关文章

  1. 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. ...

  2. 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可以链接成功,但 ...

  3. httpclient信任所有证书解决SSLException:Unrecognized SSL message,plaintext connection

    在使用 HttpClient 工具调用第三方 Http 接口时报错 javax.net.ssl.SSLException:Unrecognized SSL message,plaintext conn ...

  4. javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection

    客户端向服务器发送数据时,份两种情况,SSL单向验证和SSL双向验证 1.SSL单向验证时 代码如下: import java.io.IOException; import java.util.Has ...

  5. Unrecognized SSL message, plaintext connection? 将https 换为http 即可

    请求链接:https://59********* 升级后的项目地址有https换为了http  ,出现这个错误,改为http请求即可

  6. Unrecognized SSL message, plaintext connection--SSLSocket 代理服务器连接

    虽然java代码  URL.openconnect(proxy);已经实现了https客户端通过代理连接服务器 但个人在使用socket https代理http://www.cnblogs.com/h ...

  7. 10.整合email

    整合email <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...

  8. 19.SpringCloud实战项目-SpringCloud整合Alibaba-Nacos配置中心

    SpringCloud实战项目全套学习教程连载中 PassJava 学习教程 简介 PassJava-Learning项目是PassJava(佳必过)项目的学习教程.对架构.业务.技术要点进行讲解. ...

  9. SpringCloud实战 | 第五篇:SpringCloud整合OpenFeign实现微服务之间的调用

    一. 前言 微服务实战系列是基于开源微服务项目 有来商城youlai-mall 版本升级为背景来开展的,本篇则是讲述SpringCloud整合OpenFeign实现微服务之间的相互调用,有兴趣的朋友可 ...

  10. SpringCloud实战 | 第四篇:SpringCloud整合Gateway实现API网关

    一. 前言 微服务实战系列是基于开源微服务项目 有来商城youlai-mall 版本升级为背景来开展的,本篇则是讲述API网关使用Gateway替代Zuul,有兴趣的朋友可以进去给个star,非常感谢 ...

随机推荐

  1. 刷题笔记——1112:C语言考试练习题_一元二次方程

    题目 1112:C语言考试练习题_一元二次方程 代码 import math while True: try: a,b,c=map(float,input().strip().split()) del ...

  2. Solon Java Framework v1.12.2 发布

    一个更现代感的 Java 应用开发框架:更快.更小.更自由.没有 Spring,没有 Servlet,没有 JavaEE:独立的轻量生态.主框架仅 0.1 MB. @Controller public ...

  3. Mybatis理解

    MyBatis学习及理解 1.Mybatis简介 MyBatis是一款优秀的持久层框架,他支持定制化SQL文件.存储过程以及高级映射.避免了JDBC代码和手动设置参数以及获取结果集,Mybatis可以 ...

  4. continue语句-死循环

    continue语句 continue 使用场景:结束本次循环,继续下一次的循环 public static void main(String[] args) { for (int i = 1; i ...

  5. 2023牛客寒假算法基础集训营4 A-H+JLM

    比赛链接 A 题解 知识点:数学. 算一下发现 \(3\) 最好,\(2,4\) 并列, \(4\) 以后递减.于是,特判 \(3\) ,其他取最小值. (众所周知, \(e\) 进制最好qwq. 时 ...

  6. Mybatis Plus整合PageHelper分页的实现示例

    1.依赖引入 <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pag ...

  7. 如何注册chatgpt,如何使用chatgpt,以及chatgpt无法访问的原因。chatgpt问题总结。

    chatgpt显示所在的国家地区不可用的原因. 1:chatgpt国内是不能访问的,是需要借助魔法. 一.注册过程中的问题. \1. OpenAI或ChatGPT官网打不开.这是由于ChatGPT目前 ...

  8. html 引入 js 代码的几种方式

    一.普通加载 <script src="./abc.js"></script> 二.内嵌 <script> JavaScript 代码 < ...

  9. 真正“搞”懂HTTP协议13之HTTP2

    在前面的章节,我们把HTTP/1.1的大部分核心内容都过了一遍,并且给出了基于Node环境的一部分示例代码,想必大家对HTTP/1.1已经不再陌生,那么HTTP/1.1的学习基本上就结束了.这两篇文章 ...

  10. Vue02 Node下载安装

    转 https://blog.csdn.net/A_awen/article/details/121952701 1 下载 https://nodejs.org/en/download/ 2 安装 全 ...