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

手机网站无法访问的解决方法关键词挖掘工具网站

手机网站无法访问的解决方法,关键词挖掘工具网站,知名的网页制作公司服务好,现在有哪些培训学校准备工作 开启SMTP服务 前往你的邮箱网站,以网易邮箱为例,打开网易邮箱地址,登录你的邮箱,进入邮箱管理后台界面。点击“设置”》》“POP3/SMTP/IMAP”后,点击开启SMTP服务即可。 技术实现 Spring Boot 发送邮件验证…

准备工作

开启SMTP服务

前往你的邮箱网站,以网易邮箱为例,打开网易邮箱地址,登录你的邮箱,进入邮箱管理后台界面。点击“设置”》》“POP3/SMTP/IMAP”后,点击开启SMTP服务即可。

技术实现


Spring Boot 发送邮件验证码的功能,主要用到了spring-boot-starter-mail工具包实现邮件的发送功能,利用junit-vintage-engine工具包实现了html邮件模板功能,利用easy-captcha工具包生成随机验证码 的功能!

引入依赖

     <!--引入mail依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId></dependency><!--mail模板--><dependency><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.hamcrest</groupId><artifactId>hamcrest-core</artifactId></exclusion></exclusions></dependency><!--验证码--><dependency><groupId>com.github.whvcse</groupId><artifactId>easy-captcha</artifactId><version>1.6.2</version></dependency>

相关配置

然后再spring的配置文件中,设置mail相关配置:

spring:mail:host: smtp.yeah.comusername: 你的邮箱password: 邮箱授权码default-encoding: UTF-8protocol: smtpproperties:mail:smtp:auth: true # 启用SMTP认证starttls:enabled: true # 启用SMTP认证required: true # 必须采用加密链接

代码实现

创建一个MailService类,实现邮件发送的功能,代码如下:

import com.tarzan.nav.modules.admin.service.sys.SysConfigService;
import com.tarzan.nav.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
import java.io.UnsupportedEncodingException;
import java.util.Objects;/*** @author lsyong*/
@Component("mailService")
@Slf4j
public class MailService {private static final StringTemplateGroup templateGroup;@Resourceprivate  SysConfigService sysConfigService;static{String classpath = Objects.requireNonNull(MailService.class.getClassLoader().getResource("")).getPath();templateGroup = new StringTemplateGroup("mailTemplates", classpath + "/mailTemplates");}public static String IMG_BASE_URL;public static String ACTIVATE_CONTEXT="http:";public static String RESET_PWD_CONTEXT;@Value("${spring.mail.username}")private String username;@Resourceprivate JavaMailSender mailSender;private void sendMail(String to, String subject, String body) {MimeMessage mail = mailSender.createMimeMessage();	try {MimeMessageHelper helper = new MimeMessageHelper(mail, true, "utf-8");helper.setFrom(new InternetAddress(MimeUtility.encodeText(sysConfigService.getSiteName())+"<"+username+">").toString());helper.setTo(to);helper.setSubject(subject);helper.setText(body, true);helper.setSentDate(DateUtil.now());mailSender.send(mail);} catch (MessagingException|UnsupportedEncodingException e) {log.error(e.getMessage());}}/*** send activation mail to* @param to,key*/public void sendAccountActivationEmail(String to, String key){StringTemplate activation_temp = templateGroup.getInstanceOf("activation");activation_temp.setAttribute("img_base_url", IMG_BASE_URL);activation_temp.setAttribute("email", to);activation_temp.setAttribute("href", ACTIVATE_CONTEXT+key+"?email="+to);activation_temp.setAttribute("link", ACTIVATE_CONTEXT+key+"?email="+to);sendMail(to, sysConfigService.getSiteName()+"账户激活", activation_temp.toString());}@Asyncpublic void sendEmailCode(String to, String code){StringTemplate activation_temp = templateGroup.getInstanceOf("verificationCode");activation_temp.setAttribute("img_base_url", IMG_BASE_URL);activation_temp.setAttribute("email", to);activation_temp.setAttribute("code", code);sendMail(to, sysConfigService.getSiteName()+"邮箱验证码", activation_temp.toString());}/*** send change password link to* @param to,key*/public void sendResetPwdEmail(String to, String key){StringTemplate activation_temp = templateGroup.getInstanceOf("resetpwd");activation_temp.setAttribute("img_base_url", IMG_BASE_URL);activation_temp.setAttribute("href", RESET_PWD_CONTEXT+"?key="+key+"&email="+to);activation_temp.setAttribute("link", RESET_PWD_CONTEXT+"?key="+key+"&email="+to);sendMail(to, sysConfigService.getSiteName()+"账户密码重置", activation_temp.toString());}
}

http://www.tj-hxxt.cn/news/110608.html

相关文章:

  • 做网站的时候公共部分怎么分离好用的磁力搜索引擎
  • 大连做网站孙晓龙上海谷歌seo
  • wordpress live-calendar百度seo最成功的优化
  • wordpress管理微信公众号赣州seo排名
  • 福田做棋牌网站建设找哪家公司好国外网站推广
  • 企业网站模板上一品资源企业网站制作需要多少钱
  • 泰安企业建站公司电话近期国内热点新闻事件
  • 服务器不支持做网站是什么意思下载优化大师并安装
  • 各个做网站的有什么区别模板建站哪个平台好
  • 南通网站优化找哪家郑州全域静态管理
  • 青岛制作企业网站网络营销的表现形式有哪些
  • 哪个网站做高仿衣服批发常德今日头条新闻
  • 网络推广怎么免费做网站如何优化流程
  • 企业网站的作用百度推广开户免费
  • 大都会同行票怎么使用视频北京seo网站开发
  • 给做网站的寿全斋是真的吗求购买链接
  • 阿里免费做网站专业营销团队外包公司
  • win7做系统网站哪个好百度知道首页
  • 建网站程序下载网站的优化策略方案
  • 国内网站设计公司宁波seo外包引流推广
  • 公路机电工程建设网站搜索网站
  • 喜茶vi设计案例分析pptseo人工智能
  • 二手手机回收网站开发网络域名怎么查
  • 网站屏蔽省份seo学习论坛
  • 潍坊网站制作软件seo综合查询平台官网
  • 网站美食建设图片素材适合中层管理的培训
  • 北京网络公司注册seo怎么做排名
  • 做解析视频网站怎么赚钱网络营销事件
  • 珠海 网站建设泉州百度竞价开户
  • 网站建设存在的问题设计公司排名前十强