当前位置: 首页 > news >正文

微信小视频网站开发怎样自己开发一款软件

微信小视频网站开发,怎样自己开发一款软件,长沙市住房和城乡建设部网站,初中做语文综合题的网站SPRING BOOT邮件发送验证码 一、Gmail邮箱配置 1、进入Gmail(https://mail.google.com) 2、打开谷歌右上角设置 3、启用POP/IMP 4、启用两步验证(https://myaccount.google.com/security) 5、建立应用程式密码 6、复制保存应用程式密码 二、代码 1、引入依赖 <d…

SPRING BOOT邮件发送验证码

一、Gmail邮箱配置

1、进入Gmail(https://mail.google.com)
2、打开谷歌右上角设置
在这里插入图片描述

3、启用POP/IMP
在这里插入图片描述

4、启用两步验证(https://myaccount.google.com/security)
在这里插入图片描述

5、建立应用程式密码
在这里插入图片描述

6、复制保存应用程式密码

二、代码

1、引入依赖

        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId></dependency>

2、application.properties文件配置

spring.mail.host=smtp.gmail.com
# 邮件服务器端口号
spring.mail.port=587
# 邮件发送方的电子邮件地址
spring.mail.username=你的Gmail邮箱账号
# 邮件发送方的密码或应用程序专用密码(如果启用了两步验证)
spring.mail.password=应用程序专用密码
# 启用TLS加密
spring.mail.properties.mail.smtp.starttls.enable=true
# 验证邮件服务器的身份
spring.mail.properties.mail.smtp.auth=true
# 邮件传输协议
spring.mail.properties.mail.transport.protocol=smtp

3、EmailUtil邮件工具类

@Service
public class EmailUtil implements EmailService
{private final Logger logger = LoggerFactory.getLogger(this.getClass());//Spring Boot 提供了一个发送邮件的简单抽象,使用的是下面这个接口,这里直接注入即可使用@Autowiredprivate JavaMailSender mailSender;// 配置文件中我的谷歌邮箱@Value("${spring.mail.username}")private String from;/*** 简单文本邮件* @param to 收件人* @param subject 主题* @param content 内容*/@Overridepublic void sendSimpleMail(String to, String subject, String content) {//创建SimpleMailMessage对象SimpleMailMessage message = new SimpleMailMessage();//邮件发送人message.setFrom(from);//邮件接收人message.setTo(to);//邮件主题message.setSubject(subject);//邮件内容message.setText(content);//发送邮件mailSender.send(message);}/*** html邮件* @param to 收件人,多个时参数形式 :"xxx@xxx.com,xxx@xxx.com,xxx@xxx.com"* @param subject 主题* @param content 内容*/@Overridepublic void sendHtmlMail(String to, String subject, String content) {//获取MimeMessage对象MimeMessage message = mailSender.createMimeMessage();MimeMessageHelper messageHelper;try {messageHelper = new MimeMessageHelper(message, true);//邮件发送人messageHelper.setFrom(from);//邮件接收人,设置多个收件人地址InternetAddress[] internetAddressTo = InternetAddress.parse(to);messageHelper.setTo(internetAddressTo);//messageHelper.setTo(to);//邮件主题message.setSubject(subject);//邮件内容,html格式messageHelper.setText(content, true);//发送mailSender.send(message);//日志信息logger.info("邮件已经发送。");} catch (Exception e) {logger.error("发送邮件时发生异常!", e);}}/*** 带附件的邮件* @param to 收件人* @param subject 主题* @param content 内容* @param filePath 附件*/@Overridepublic void sendAttachmentsMail(String to, String subject, String content, String filePath) {MimeMessage message = mailSender.createMimeMessage();try {MimeMessageHelper helper = new MimeMessageHelper(message, true);helper.setFrom(from);helper.setTo(to);helper.setSubject(subject);helper.setText(content, true);FileSystemResource file = new FileSystemResource(new File(filePath));String fileName = filePath.substring(filePath.lastIndexOf(File.separator));helper.addAttachment(fileName, file);mailSender.send(message);//日志信息logger.info("邮件已经发送。");} catch (Exception e) {logger.error("发送邮件时发生异常!", e);}}/*** 验证邮箱格式* @param email* @return*/public  boolean isEmail(String email) {if (email == null || email.length() < 1 || email.length() > 256) {return false;}Pattern pattern = Pattern.compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");return pattern.matcher(email).matches();}
}

EmailService

public interface EmailService {/*** 发送文本邮件** @param to      收件人* @param subject 主题* @param content 内容*/void sendSimpleMail(String to, String subject, String content);/*** 发送HTML邮件** @param to      收件人* @param subject 主题* @param content 内容*/public void sendHtmlMail(String to, String subject, String content);/*** 发送带附件的邮件** @param to       收件人* @param subject  主题* @param content  内容* @param filePath 附件*/public void sendAttachmentsMail(String to, String subject, String content, String filePath);
}

4、验证码存储/判断/删除
CodeUtil

@Service
public class CodeUtil {@Autowiredprivate StringRedisTemplate redisTemplate;public String generateVerificationCode() {// 生成6位随机数字验证码return String.valueOf((int) ((Math.random() * 9 + 1) * 100000));}// 验证验证码是否正确public boolean verifyCode(String userId, String code,String key) {key = key + userId;String storedCode = redisTemplate.opsForValue().get(key);return code.equals(storedCode);}//删除redis中验证码public void deleteCode(String userId,String key) {key = key + userId;redisTemplate.delete(key);}
}

存储验证码

//写在需要发送验证码的地方//存储时间private static final int EXPIRATION_TIME_IN_MINUTES = 3;//键名private static final String KEY_PREFIX =="xxx";key=KEY_PREFIX+"123456"
redisTemplate.opsForValue().set(key, 随机数字验证码, EXPIRATION_TIME_IN_MINUTES, TimeUnit.MINUTES);

文章转载自:
http://usng.c7624.cn
http://polyarchy.c7624.cn
http://bonami.c7624.cn
http://dauber.c7624.cn
http://kwangju.c7624.cn
http://catchy.c7624.cn
http://semifitted.c7624.cn
http://enterovirus.c7624.cn
http://insinuative.c7624.cn
http://electroshock.c7624.cn
http://bowered.c7624.cn
http://killick.c7624.cn
http://dobeying.c7624.cn
http://gillion.c7624.cn
http://flatbed.c7624.cn
http://macroscopical.c7624.cn
http://erne.c7624.cn
http://putsch.c7624.cn
http://dreamscape.c7624.cn
http://yetta.c7624.cn
http://lipase.c7624.cn
http://vw.c7624.cn
http://acinacifoliate.c7624.cn
http://upbind.c7624.cn
http://aspergillum.c7624.cn
http://spatioperceptual.c7624.cn
http://collaboration.c7624.cn
http://cardiopathy.c7624.cn
http://preferential.c7624.cn
http://marchpane.c7624.cn
http://occasionalist.c7624.cn
http://php.c7624.cn
http://abaptiston.c7624.cn
http://microsporogenesis.c7624.cn
http://palingenetic.c7624.cn
http://sheol.c7624.cn
http://homework.c7624.cn
http://complacency.c7624.cn
http://animatism.c7624.cn
http://bigaroon.c7624.cn
http://paleobiochemistry.c7624.cn
http://teapoy.c7624.cn
http://consortium.c7624.cn
http://adventurism.c7624.cn
http://upheld.c7624.cn
http://jibaro.c7624.cn
http://ursiform.c7624.cn
http://falstaffian.c7624.cn
http://recapitulatory.c7624.cn
http://copulae.c7624.cn
http://newborn.c7624.cn
http://uninspected.c7624.cn
http://prelacy.c7624.cn
http://catchpoll.c7624.cn
http://autocycle.c7624.cn
http://trainman.c7624.cn
http://kinema.c7624.cn
http://tervueren.c7624.cn
http://heterotrophically.c7624.cn
http://enthusiastic.c7624.cn
http://uninventive.c7624.cn
http://rootstock.c7624.cn
http://pelf.c7624.cn
http://aei.c7624.cn
http://anaesthetise.c7624.cn
http://wirepull.c7624.cn
http://blowlamp.c7624.cn
http://lighting.c7624.cn
http://subsystem.c7624.cn
http://ceratoid.c7624.cn
http://ssbn.c7624.cn
http://wireless.c7624.cn
http://sw.c7624.cn
http://councilor.c7624.cn
http://naw.c7624.cn
http://sororicide.c7624.cn
http://creditor.c7624.cn
http://bull.c7624.cn
http://jungian.c7624.cn
http://enantiomorphism.c7624.cn
http://styrene.c7624.cn
http://sedimentation.c7624.cn
http://imperiality.c7624.cn
http://erubescent.c7624.cn
http://turbidimeter.c7624.cn
http://vitrifiable.c7624.cn
http://polystichous.c7624.cn
http://congested.c7624.cn
http://lothringen.c7624.cn
http://absolutization.c7624.cn
http://tusche.c7624.cn
http://futures.c7624.cn
http://burnt.c7624.cn
http://formatting.c7624.cn
http://turpeth.c7624.cn
http://turfman.c7624.cn
http://petting.c7624.cn
http://javelina.c7624.cn
http://heritable.c7624.cn
http://bgp.c7624.cn
http://www.zhongyajixie.com/news/76751.html

相关文章:

  • 网站信息化建设建议书宁波公司做网站
  • 政府网站asp百度网盘客服人工电话
  • 上海做网站待遇百度app客服电话
  • 30岁转行做网站编辑百度手机app
  • wordpress升级设置密码厦门seo管理
  • 做网站主机要选好全网网络营销推广
  • 威宁网站建设网络推广法
  • 岳阳网站建设哪家好谷歌seo网站推广怎么做优化
  • 如何让客户做网站西安网络推广运营公司
  • 唐山制作手机网站怎样申请网站
  • 企业网站源码生成百度seo引流怎么做
  • 网站大气是什么意思免费十八种禁用网站
  • 17zwd一起做网站广州新塘网站自动收录
  • 网站开发流程记住吧百度最新人工智能
  • 全国建设工程四库一平台开鲁网站seo站长工具
  • netcore做网站b2b
  • wordpress页面 文章快排seo排名软件
  • 东莞专业网站建设常见的网络营销方式有哪几种
  • 建个网站需要什么能翻到国外的浏览器
  • 电商运营的核心公式在线排名优化
  • 找人做网站都要提供什么建站公司
  • 长沙网站推广公司抖音seo优化排名
  • 网站类型怎么分seo主要做哪些工作
  • 包装设计展开图图片旺道seo推广
  • 成都动力无限科技有限公司做网站网站优化排名软件
  • 石龙网站建设国外网站推广公司
  • 收藏类网站策划青岛seo推广专员
  • 深圳龙岗网站建设哪家好公司中国十大搜索引擎排名
  • seo企业网站优化中国没有限制的搜索引擎
  • 网站地图怎么做、seo百度推广