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

浙江建站优化品牌公众号开发网站公司

浙江建站优化品牌,公众号开发网站公司,搜索引擎营销的原理,网站上的广告位是怎么做的Spring boot 发送文本邮件 和 html模板邮件 提示#xff1a;这里使用 spring-boot-starter-mail 发送文本邮件 和 html模板邮件 文章目录 Spring boot 发送文本邮件 和 html模板邮件一、开启QQ邮箱里的POP3/SMTP服务①#xff1a;开启步骤 二、简单配置①#xff1a;引入依赖…Spring boot 发送文本邮件 和 html模板邮件 提示这里使用 spring-boot-starter-mail 发送文本邮件 和 html模板邮件 文章目录 Spring boot 发送文本邮件 和 html模板邮件一、开启QQ邮箱里的POP3/SMTP服务①开启步骤 二、简单配置①引入依赖②yml配置 三、发送纯文本文件①写个工具类②在业务层调用方法发送即可③发送成功 四、发送Html模板邮件①定义一个Html模板②在工具类中新增两个方法③发送成功 提示以下是本篇文章正文内容下面案例可供参考 一、开启QQ邮箱里的POP3/SMTP服务 ①开启步骤 1.邮箱设置 --账号 2.开启服务并复制 授权码 二、简单配置 ①引入依赖 !-- 邮件发送--dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-mail/artifactId/dependency②yml配置 mail:username: xxxxfoxmail.com# QQ邮箱应该使用授权码password: *****ek***## 邮箱服务器地址 smtp.qq.comhost: smtp.qq.com#使用SMTPS协议465端口port: 465# ssl 配置properties:mail.smtp.starttls.required: trueencoding: UTF-8mail.smtp.ssl.enable: truemail.smtp.auth: truemail.smtp.socketFactory.port: 465mail.smtp.socketFactory.class: javax.net.ssl.SSLSocketFactorymail.smtp.socketFactory.fallback: false三、发送纯文本文件 ①写个工具类 Component Slf4j public class UtilsSendCode {Value(${spring.mail.username})private String sender;Resourceprivate JavaMailSenderImpl mailSender;/*** 发送纯文字邮件* param to 收件人* param subject 主题* param content 内容*/public void sendSimpleMail(String to, String subject, String content) {//创建SimpleMailMessage对象SimpleMailMessage message new SimpleMailMessage();//邮件发送人message.setFrom(sender);//邮件接收人message.setTo(to);//邮件主题message.setSubject(subject);//邮件内容message.setText(content);//发送邮件try {mailSender.send(message);log.info(邮件接收人to主题subject内容content邮件发送成功);}catch (Exception e){log.error(邮件接收人to主题subject内容content邮件发送出现异常);log.error(异常信息为e.getMessage());}} }②在业务层调用方法发送即可 // 开始发送邮件utilsSendCode.sendSimpleMail(xxxxxxgmail.com, 验证码, 123456);③发送成功 1.发送测试 2.收到验证码 四、发送Html模板邮件 ①定义一个Html模板 1.template/mailTemplate.ftl !DOCTYPE html html xmlns:thhttp://www.thymeleaf.org headmeta charsetutf-8meta http-equivX-UA-Compatible contentIEedgemeta namedescription contentemail codemeta nameviewport contentwidthdevice-width, initial-scale1 /head !--邮箱验证码模板-- body div stylebackground-color:#ECECEC; padding: 35px;table cellpadding0 aligncenterstylewidth: 800px;height: 100%; margin: 0px auto; text-align: left; position: relative; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; font-size: 14px; font-family:微软雅黑, 黑体; line-height: 1.5; box-shadow: rgb(153, 153, 153) 0px 0px 5px; border-collapse: collapse; background-position: initial initial; background-repeat: initial initial;background:#fff;tbodytrth valignmiddlestyleheight: 25px; line-height: 25px; padding: 15px 35px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: RGB(148,0,211); background-color: RGB(148,0,211); border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px;font face微软雅黑 size5 stylecolor: rgb(255, 255, 255); 这里输入name/font/th/trtrtd styleword-break:break-alldiv stylepadding:25px 35px 40px; background-color:#fff;opacity:0.8;h2 stylemargin: 5px 0px; font color#333333 styleline-height: 20px; font styleline-height: 22px; size4尊敬的用户/font/font/h2!-- 中文 --p您好感谢您使用****您的账号正在进行邮箱验证验证码为font color#ff8c00{0}/font有效期30分钟请尽快填写验证码完成验证/pbr!-- 英文 --h2 stylemargin: 5px 0px; font color#333333 styleline-height: 20px; font styleline-height: 22px; size4Dear user:/font/font/h2pHello! Thanks for using *****, your account is being authenticated by email, theverification code is:font color#ff8c00{0}/font, valid for 30 minutes. Please fill in the verification code as soon aspossible!/pdiv stylewidth:100%;margin:0 auto;div stylepadding:10px 10px 0;border-top:1px solid #ccc;color:#747474;margin-bottom:20px;line-height:1.3em;font-size:12px;p****团队/pp联系我们********/pbrp此为系统邮件请勿回复brPlease do not reply to this system email/p!--p©***/p--/div/div/div/td/tr/tbody/table /div /body /html ②在工具类中新增两个方法 根据模板生成邮件内容 /*** 根据模板生成邮件内容* param code 验证码* return*/public String buildContent(String code) {//加载邮件html模板ClassPathResource resource new ClassPathResource(template/mailTemplate.ftl);InputStream inputStream null;BufferedReader fileReader null;StringBuffer buffer new StringBuffer();String line ;try {inputStream resource.getInputStream();fileReader new BufferedReader(new InputStreamReader(inputStream));while ((line fileReader.readLine()) ! null) {buffer.append(line);}} catch (Exception e) {log.error(发送邮件读取模板失败{}, e.toString());} finally {if (fileReader ! null) {try {fileReader.close();} catch (IOException e) {e.printStackTrace();}}if (inputStream ! null) {try {inputStream.close();} catch (IOException e) {e.printStackTrace();}}}//替换html模板中的参数return MessageFormat.format(buffer.toString(), code);} 发送HTML邮件 /*** 发送HTML邮件* param to 收件人* param subject 主题* param code 内容验证码*/public void sendEmailByHtml(String to, String subject, String code) {//获取MimeMessage对象MimeMessage message mailSender.createMimeMessage();MimeMessageHelper messageHelper;try {messageHelper new MimeMessageHelper(message, true);//邮件发送人messageHelper.setFrom(sender);//邮件接收人messageHelper.setTo(to);//邮件主题message.setSubject(subject);//邮件内容html格式messageHelper.setText(buildContent(code), true);//发送mailSender.send(message);//日志信息log.info(邮件已经发送。);} catch (MessagingException e) {log.error(发送邮件时发生异常, e);}}③发送成功 1.业务层调用方法直接发送即可 // 开始发送邮件utilsSendCode.sendEmailByHtml(xxxx9gmail.com, 验证码, 559955);2.测试请求 3.发送成功
http://www.pierceye.com/news/249900/

相关文章:

  • 网站系统问题解决措施上海网站建设系
  • c 做网站简单吗ui设计需要学什么软件
  • 网站建设app开发公司国内免备案空间
  • nas 支持做网站dedecms 做影网站
  • 网上商城网站模板广州建设技术职业学院
  • 养生网站模板下载山东网站建设哪家专业
  • 最新电子产品网站模板网站建设公司 腾佳
  • 跟公司产品做网站用什么程序做网站最好优化
  • 在线代理网页浏览网站山东省城乡住房建设厅网站
  • 网站建设需准备什么彩页模板图片
  • 怎么用网站源码建站网站换空间步骤
  • 酒店网站开发回扣商丘企业网站建设服务
  • 网站建设策划解决方案河北自助建站系统平台
  • 有没有做高仿手表的网站设计师的职责
  • struts2 做的网站seo公司怎样找客户
  • 帮别人做网站赚钱吗中山快速建站合作
  • 保靖网站建设做网站要运用到代码吗
  • 我用织梦5.7做个网站应该把淘宝客店铺链接放到哪frontpage可以制作网页吗
  • 潍坊优化网站排名在线网页设计培训机构
  • c做的网站ps做 网站标准尺寸
  • 老虎淘客系统可以做网站吗wordpress po mo
  • 网站的建设与维护那个网站做图片好
  • 昆山网站建设详细方案建设企业网站初始必备的六大功能
  • 做网站是前端还是后端网站规划 设计 制作 发布与管理过程
  • 黄山网站开发威县做网站哪里便宜
  • 网站怎么分类视频聚合网站怎么做不侵权
  • 有没有做问卷还能赚钱的网站套别人的网站模板吗
  • 东莞做汽车有没有买票的网站做谷歌推广一个月赚10万
  • 抚州城乡建设厅网站建设局官网查询
  • 汉中微信网站建设装修3d效果图怎么制作