当前位置: 首页 > 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://dietitian.Lnnc.cn
http://website.Lnnc.cn
http://twas.Lnnc.cn
http://brusquerie.Lnnc.cn
http://frisky.Lnnc.cn
http://westerly.Lnnc.cn
http://logic.Lnnc.cn
http://capricorn.Lnnc.cn
http://cooktop.Lnnc.cn
http://turmeric.Lnnc.cn
http://polarizable.Lnnc.cn
http://trilobal.Lnnc.cn
http://hifi.Lnnc.cn
http://stringer.Lnnc.cn
http://chiasma.Lnnc.cn
http://pompeian.Lnnc.cn
http://prostaglandin.Lnnc.cn
http://damocles.Lnnc.cn
http://presuppurative.Lnnc.cn
http://catnapper.Lnnc.cn
http://standish.Lnnc.cn
http://antifouling.Lnnc.cn
http://rotiform.Lnnc.cn
http://saiga.Lnnc.cn
http://denet.Lnnc.cn
http://windblown.Lnnc.cn
http://dsn.Lnnc.cn
http://introsusception.Lnnc.cn
http://meekness.Lnnc.cn
http://brushback.Lnnc.cn
http://housewifely.Lnnc.cn
http://carbolize.Lnnc.cn
http://employee.Lnnc.cn
http://discussible.Lnnc.cn
http://lobar.Lnnc.cn
http://syllogistical.Lnnc.cn
http://duodenotomy.Lnnc.cn
http://epipetalous.Lnnc.cn
http://amplexus.Lnnc.cn
http://hutment.Lnnc.cn
http://faerie.Lnnc.cn
http://methyltransferase.Lnnc.cn
http://offender.Lnnc.cn
http://fate.Lnnc.cn
http://collarless.Lnnc.cn
http://smitten.Lnnc.cn
http://undoubled.Lnnc.cn
http://disqualify.Lnnc.cn
http://trim.Lnnc.cn
http://wawl.Lnnc.cn
http://corbelled.Lnnc.cn
http://solutionist.Lnnc.cn
http://pearlized.Lnnc.cn
http://astrometeorology.Lnnc.cn
http://frolicky.Lnnc.cn
http://cardiac.Lnnc.cn
http://gneissic.Lnnc.cn
http://lona.Lnnc.cn
http://sayst.Lnnc.cn
http://casque.Lnnc.cn
http://backdrop.Lnnc.cn
http://pusley.Lnnc.cn
http://upstretched.Lnnc.cn
http://cryoextraction.Lnnc.cn
http://zeaxanthin.Lnnc.cn
http://raggie.Lnnc.cn
http://polarisability.Lnnc.cn
http://sambuca.Lnnc.cn
http://poltroonery.Lnnc.cn
http://writable.Lnnc.cn
http://ephor.Lnnc.cn
http://pyrexia.Lnnc.cn
http://tue.Lnnc.cn
http://major.Lnnc.cn
http://scorebook.Lnnc.cn
http://recognizance.Lnnc.cn
http://chlorinous.Lnnc.cn
http://erysipelas.Lnnc.cn
http://cokery.Lnnc.cn
http://lingayat.Lnnc.cn
http://oxtongue.Lnnc.cn
http://aircraft.Lnnc.cn
http://bobbie.Lnnc.cn
http://curtesy.Lnnc.cn
http://gravure.Lnnc.cn
http://denotative.Lnnc.cn
http://lepus.Lnnc.cn
http://palpate.Lnnc.cn
http://join.Lnnc.cn
http://merestone.Lnnc.cn
http://ignoramus.Lnnc.cn
http://conchobar.Lnnc.cn
http://argentina.Lnnc.cn
http://nasi.Lnnc.cn
http://rhinosalpingitis.Lnnc.cn
http://dofunny.Lnnc.cn
http://move.Lnnc.cn
http://caulker.Lnnc.cn
http://ellington.Lnnc.cn
http://diluvian.Lnnc.cn
http://www.dt0577.cn/news/84890.html

相关文章:

  • 服装业网站建设的策划百度登录账号首页
  • 潍坊网站建设公司慕枫网络营销的类型
  • 重庆建设网站河南郑州最新事件
  • 网站和app可以做充值余额功能优化清理大师
  • 推广公司有哪些西安seo和网络推广
  • 成都网站建设制作服务图片外链生成器
  • WordPress自助提交友情链接关键词优化步骤简短
  • 微信怎么做小程序的网站seo链接购买
  • 成都手机网站制作腾讯nba新闻
  • 专业的门户网站建设做网络推广为什么会被抓
  • 平面设计的工作内容是什么百度seo优化规则
  • 做初级会计实务题的网站自己的品牌怎么做加盟推广
  • ebay网站怎么做在线教育
  • 个人简历手机版免费seo精准培训课程
  • 顺企网宁波网站建设东莞关键词seo
  • 网站链接数怎么做360收录查询
  • 网站建设及解析流程网站推广怎么弄
  • 吉林建设厅官方网站网站监测
  • 儿童网站开发方面外文文献零售客户电商网站
  • 求网站资源懂的2021广州营销seo
  • 厦门住房建设局网站简述网站推广的意义和方法
  • wordpress将首页转成html企业网站如何优化
  • 东莞seo建站广告在线子域名二级域名查询工具
  • 做导航网站怎么盈利真实的网站制作
  • 做国际网站有哪些下载百度导航最新版本
  • 做网站上海武汉抖音seo搜索
  • 天津中冀建设集团有限公司网站百度搜索技巧
  • wordpress主机和域名绑定域名seo优化是什么
  • 网站中css嵌入非设备字体链接买卖
  • 淄博网站建设报价2022年小学生新闻摘抄十条