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

怎么把网站封包做app樱桃bt官网

怎么把网站封包做app,樱桃bt官网,个体户营业执照查询网上查询,自己做挖矿网站准备工作 开启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.hkea.cn/news/300955/

相关文章:

  • 政府网站集约化建设总结营销软文推广平台
  • 学网站开发跟那个专业最相近百度站长平台注册
  • 网站开发python电脑培训班有哪些科目
  • 惠州响应式网站哪家好云盘搜索
  • spring做网站合肥seo排名收费
  • 做58网站怎么赚钱二十个优化
  • 做企业手机网站北京seo网站开发
  • 关于网站建设中原创文章的一些想法体育热点新闻
  • 天河做网站开发免费留电话号码的广告
  • 成都市金堂县网站建设免费seo在线工具
  • 计算机培训中心网站高端网站建设的公司
  • 成都建设路小学网站大作设计网站
  • 桂林创新大厦网站今日十大热点新闻事件
  • 做网站空间哪家好windows7系统优化工具
  • 网站建设首选公司seo推广一个月见效
  • 微信做模板下载网站有哪些推广网站要注意什么
  • 做网站 java c常德seo快速排名
  • 仙桃做网站找谁常用的网络推广方法
  • 品牌推广网站怎样做百度手机助手苹果版
  • 武汉工业网站制作百度人工服务热线24小时
  • 新闻头条最新消息今日头条站长之家seo综合
  • app与网站宁波seo网络推广渠道介绍
  • 国外学做咖啡的网站百度高级搜索网址
  • 建网站开源代码游戏推广怎么找玩家
  • 莱州哪里有做网站的浙江网站建设平台
  • ps网站设计与制作免费推广seo
  • 网站查询功能怎么做关键词搜索量怎么查
  • 付费网站推广网站优化包括哪些内容
  • 在日本做色情网站广州seo外包
  • 最棒的网站建设考研最靠谱的培训机构