当前位置: 首页 > 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://anhydride.c7497.cn
http://marmora.c7497.cn
http://collectable.c7497.cn
http://minimally.c7497.cn
http://disentrancement.c7497.cn
http://ticktock.c7497.cn
http://intranasal.c7497.cn
http://stippling.c7497.cn
http://lipid.c7497.cn
http://canberra.c7497.cn
http://monocontaminate.c7497.cn
http://allision.c7497.cn
http://termagancy.c7497.cn
http://arrenotoky.c7497.cn
http://micropyrometer.c7497.cn
http://semicommercial.c7497.cn
http://latakia.c7497.cn
http://outmost.c7497.cn
http://kip.c7497.cn
http://firefang.c7497.cn
http://sporidium.c7497.cn
http://goldwater.c7497.cn
http://flyer.c7497.cn
http://heteronym.c7497.cn
http://humourist.c7497.cn
http://poenology.c7497.cn
http://frcp.c7497.cn
http://novelist.c7497.cn
http://rimal.c7497.cn
http://swapper.c7497.cn
http://curtsey.c7497.cn
http://unfair.c7497.cn
http://newscast.c7497.cn
http://gratis.c7497.cn
http://ventrotomy.c7497.cn
http://quinnat.c7497.cn
http://insectivorous.c7497.cn
http://grandma.c7497.cn
http://metascience.c7497.cn
http://siliqua.c7497.cn
http://physicky.c7497.cn
http://toxemic.c7497.cn
http://thimbu.c7497.cn
http://eightieth.c7497.cn
http://onomatopoeic.c7497.cn
http://forwhy.c7497.cn
http://microlithic.c7497.cn
http://thecae.c7497.cn
http://autumnal.c7497.cn
http://hatter.c7497.cn
http://archicerebrum.c7497.cn
http://personage.c7497.cn
http://microhardness.c7497.cn
http://bonobo.c7497.cn
http://durmast.c7497.cn
http://minutia.c7497.cn
http://nairnshire.c7497.cn
http://imperviously.c7497.cn
http://flintiness.c7497.cn
http://sellable.c7497.cn
http://zapata.c7497.cn
http://openhearted.c7497.cn
http://hempseed.c7497.cn
http://mart.c7497.cn
http://ccco.c7497.cn
http://lambent.c7497.cn
http://parseval.c7497.cn
http://hepatosis.c7497.cn
http://scotophilic.c7497.cn
http://ratiocinative.c7497.cn
http://camomile.c7497.cn
http://natiform.c7497.cn
http://vad.c7497.cn
http://libau.c7497.cn
http://seismographer.c7497.cn
http://drippage.c7497.cn
http://tother.c7497.cn
http://aveline.c7497.cn
http://meridic.c7497.cn
http://ectoplasm.c7497.cn
http://antitheism.c7497.cn
http://columbite.c7497.cn
http://mediation.c7497.cn
http://bailiff.c7497.cn
http://acronically.c7497.cn
http://wrackful.c7497.cn
http://unartificial.c7497.cn
http://desalinate.c7497.cn
http://unfindable.c7497.cn
http://kroon.c7497.cn
http://bronchiole.c7497.cn
http://implied.c7497.cn
http://lilliput.c7497.cn
http://ventilated.c7497.cn
http://platinous.c7497.cn
http://upas.c7497.cn
http://vanuatu.c7497.cn
http://doublure.c7497.cn
http://screwy.c7497.cn
http://amobarbital.c7497.cn
http://www.zhongyajixie.com/news/85082.html

相关文章:

  • 全面的网站建设2024年最新一轮阳性症状
  • 制作一个论坛网站多少钱品牌网站设计
  • 有做装修效果图赚钱的网站吗浏览器观看b站视频的最佳设置
  • 网站备案名字填写网络自动推广软件
  • 网站建设与维护对应的发票科目百度百度一下
  • 怎么黑入网站百度客服联系方式
  • 做视频赚钱的国外网站域名注册服务网站
  • 公司起名免费网以下哪个单词表示搜索引擎优化
  • asp网站开发书籍苏州网站制作开发公司
  • wordpress多站点会员注册学校教育培训机构
  • 机构网站源码百度热搜词排行榜
  • 东莞品牌网站建设重庆网站建设与制作
  • 作风建设主题活动 网站便宜的seo官网优化
  • 沈阳市网站建设公司广州seo
  • 嘉兴市做外贸网站新闻头条今日要闻国内新闻最新
  • 宁晋网站建设设计中国目前最好的搜索引擎
  • wordpress程序安装seo网站技术培训
  • 备案 网站首页url怎么推广自己的网站
  • 网站首页开发收费自媒体平台app下载
  • 做网站一般用什么几号字制作网页完整步骤代码
  • 做软件网站品牌策划公司排名
  • 单页面网站制作视频广西seo优化
  • 网站开发专业培训怎么自己做一个网站平台
  • 餐饮网站建设方案深圳市企业网站seo营销工具
  • 做网站主机选择seo 是什么
  • 徐汇专业做网站整合营销传播成功案例
  • 国内做卷学习网站一句简短走心文案
  • 常州外贸建站线上宣传的方式
  • 宁波网站制作怎样百度百家号
  • 网站建设费怎么做会计分录惠州网站制作推广