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,非常感谢 ...
随机推荐
- 《Effective C++》关于const,define等总结
(将每一条item的总结和自己的理解给记录下来,以后有需要的话可以再回头参阅这些资料,不懂的再翻书温故.) Item 02:尽量以const ,enum,inline替换#define #define ...
- [Untiy]贪吃蛇大作战(三)——商店界面
游戏商店界面: 实际的效果图如下: 要实现这个滑动,首先我们需要,一个内容显示区域,一个内容滚动区域,如下图: 其中ItemContent挂载的组件如下: 红框标注的地方是右方的滑动块. 然后Item ...
- 学习ASP.NET Core Blazor编程系列二十二——登录(1)
学习ASP.NET Core Blazor编程系列文章之目录 学习ASP.NET Core Blazor编程系列一--综述 学习ASP.NET Core Blazor编程系列二--第一个Blazor应 ...
- 【随笔记】T507 Android10 EC200U-CN 4G Cat1 移植
基本信息 硬件信息 硬件平台:T507 (Android 10 Linux 4.9) 模组型号:EC200U-CN(Cat1)(展讯芯片) 相关文件 代理提供 longan/kernel/linux- ...
- 【随笔记】NDK 编译开源库 nghttp2/openssl/curl
工作中有遇到需要使用支持 http2 访问的 https 安全加密的开源库,便于使用 http2 与云端通信,经过调研发现 libcurl 可以满足需求,但是 libcurl 本身也是需要依赖于 ng ...
- vuex 的使用详解
一.vuex 概述 (一)组件之间共享数据的方式 但是这三种方案,只适合小范围的数据共享,如果我们需要频繁的大范围的进行组件之间的数据共享,那么我们就适合使用 vuex (二)vuex 是什么 主要实 ...
- Vue.config.js配置 最新可用版本
最近 在学前端,然后,学了这个vue-cli脚手架,虽然,我这个vue-cli还不算入门,后我会把这个笔记补上 下面是我的Vue.config.js的配置,我感觉这个复用的程度高,所以记下 了这个随笔 ...
- @mapper注解
1.标记这是一个映射接口,这样子写还是需要写xml文件 package com.atguigu.springcloud.dao; import com.atguigu.springcloud.enti ...
- Vue框架:6、Vue组件间通信,动态组件,插槽,计算属性,监听属性
目录 前端开发之Vue框架 一.Vue组件间通信 1.组件间通讯父传子 2.组件间通讯子传父 3.ref属性 二.动态组件 1.不使用动态组件 2.使用动态组件 3.keep-alive保持组件不销毁 ...
- 中南大学CSU2022-2023级C语言期中考试机试答案
卡在出线概率了.40%,没想到遍历时反了,我去. 1.时钟加法 1 #include<stdio.h> 2 3 #include<string.h> 4 5 #include& ...