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

网站建设工作流程html网页升级访问更新中狼

网站建设工作流程html,网页升级访问更新中狼,中国城乡住房建设厅官网,wordpress 4.8上传漏洞目录 1、创建一个基本的SpringBoot项目#xff0c;pom文件导入发送邮件的依赖 2、application.yml 文件配置配置邮件发送信息 3、创建IEmailService 接口文件#xff0c;定义邮件发送的接口 4、创建IEmailService接口的实现类EmailService.java 文件 5、新建邮件发送模板 ema…                目录 1、创建一个基本的SpringBoot项目pom文件导入发送邮件的依赖 2、application.yml 文件配置配置邮件发送信息 3、创建IEmailService 接口文件定义邮件发送的接口 4、创建IEmailService接口的实现类EmailService.java 文件 5、新建邮件发送模板 email.html 6、新建测试类主要代码如下 7、效果截图 邮件发送功能基本是每个完整业务系统要集成的功能之一今天小编给大家介绍一下SpringBoot实现邮件发送功能希望对大家能有所帮助 今天主要给大家分享简单邮件发送、HTML邮件发送、包含附件的邮件发送三个例子具体源码链接在文章末尾有需要的朋友可以自己下载学习一下。 1、创建一个基本的SpringBoot项目pom文件导入发送邮件的依赖 !--邮件发送依赖包-- dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-mail/artifactId /dependency !--freemarker制作Html邮件模板依赖包-- dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-freemarker/artifactId /dependency 2、application.yml 文件配置配置邮件发送信息 spring: mail: host: smtp.qq.com username: xxxqq.com #发件人邮箱 password: xxxxx #授权码 protocol: smtp properties.mail.smtp.auth:true properties.mail.smtp.port:465#发件邮箱端口 properties.mail.display.sendmail: xiaoMing properties.mail.display.sendname: xiaoming properties.mail.smtp.starttls.enable:true properties.mail.smtp.starttls.required:true properties.mail.smtp.ssl.enable:true#是否启用ssl default-encoding: utf-8#编码格式 freemarker: cache:false settings: classic_compatible:true suffix: .html charset: UTF-8 template-loader-path: classpath:/templates/ 3、创建IEmailService 接口文件定义邮件发送的接口 package com.springboot.email.email.service;import javax.mail.MessagingException; import java.util.List;public interface IEmailService {/*** 发送简单文本邮件*/void sendSimpleMail(String receiveEmail, String subject, String content);/*** 发送HTML格式的邮件*/void sendHtmlMail(String receiveEmail, String subject, String emailContent) throws MessagingException;/*** 发送包含附件的邮件*/void sendAttachmentsMail(String receiveEmail, String subject, String emailContent, ListString filePathList) throws MessagingException; } 4、创建IEmailService接口的实现类EmailService.java 文件 package com.springboot.email.email.service.impl;import com.springboot.email.email.service.IEmailService; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.FileSystemResource; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.stereotype.Service;import javax.annotation.Resource; import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; import java.io.File; import java.util.List; Service public class EmailServiceImpl implements IEmailService {Resourceprivate JavaMailSender mailSender;Value(${spring.mail.username})private String fromEmail;/*** 发送简单文本邮件*/public void sendSimpleMail(String receiveEmail, String subject, String content) {SimpleMailMessage message new SimpleMailMessage();message.setFrom(fromEmail);message.setTo(receiveEmail);message.setSubject(subject);message.setText(content);mailSender.send(message);}/*** 发送Html格式的邮件*/public void sendHtmlMail(String receiveEmail,String subject,String emailContent) throws MessagingException{init(receiveEmail, subject, emailContent, mailSender, fromEmail);}public static void init(String receiveEmail, String subject, String emailContent, JavaMailSender mailSender, String fromEmail) throws MessagingException {MimeMessage message mailSender.createMimeMessage();MimeMessageHelper helpernew MimeMessageHelper(message,true);helper.setFrom(fromEmail);helper.setTo(receiveEmail);helper.setSubject(subject);helper.setText(emailContent,true);mailSender.send(message);}/*** 发送包含附件的邮件*/public void sendAttachmentsMail(String receiveEmail, String subject, String emailContent, ListString filePathList) throws MessagingException {MimeMessage message mailSender.createMimeMessage();//带附件第二个参数trueMimeMessageHelper helper new MimeMessageHelper(message, true);helper.setFrom(fromEmail);helper.setTo(receiveEmail);helper.setSubject(subject);helper.setText(emailContent, true);//添加附件资源for (String item : filePathList) {FileSystemResource file new FileSystemResource(new File(item));String fileName item.substring(item.lastIndexOf(File.separator));helper.addAttachment(fileName, file);}//发送邮件mailSender.send(message);} } 5、新建邮件发送模板 email.html !DOCTYPE html html head langenmeta charsetUTF-8/title/titlestyletd {border: black 1px solid;}/style /head body h1工资条/h1 table styleborder: black 1px solid;width: 750pxtheadtd序号/tdtd姓名/tdtd基本工资/tdtd在职天数/tdtd奖金/tdtd社保/tdtd个税/tdtd实际工资/td/theadtbodytrtd${salary.index}/tdtd${salary.name}/tdtd${salary.baseSalary}/tdtd${salary.inDays}/tdtd${salary.reward}/tdtd${salary.socialSecurity}/tdtd${salary.tax}/tdtd${salary.actSalary}/td/tr/tbody /table /body /html 6、新建测试类主要代码如下 /*** 测试简单文本文件*/ Test public void EmailTest() {emailService.sendSimpleMail(hgmyzoutlook.com, 测试邮件, springboot 邮件测试); }Test public void HtmlEmailTest() throws MessagingException {String receiveEmail hgmyzoutlook.com;String subject Spring Boot 发送Html邮件测试;String emailContent h2您好/h2p这里是一封Spring Boot 发送的邮件祝您天天开心img srchttps://p3.toutiaoimg.com/origin/tos-cn-i-qvj2lq49k0/a43f0608912a4ecfa182084e397e4b81?frompc width500 height300 //p a hrefhttps://programmerblog.xyz titleIT技术分享设社区 targer_blankIT技术分享设社区/a;emailService.sendHtmlMail(receiveEmail, subject, emailContent); }Test public void templateEmailTest() throws IOException, TemplateException, MessagingException {String receiveEmail hgmyzoutlook.com;String subject Spring Boot 发送Templete邮件测试;//添加动态数据替换模板里面的占位符SalaryVO salaryVO new SalaryVO(1, 小明, 2, 9000.00, 350.06, 280.05, 350.00, 7806.00);Template template freeMarkerConfigurer.getConfiguration().getTemplate(email.html);//将模板文件及数据渲染完成之后转换为html字符串MapString, Object model new HashMap();model.put(salary, salaryVO);String templateHtml FreeMarkerTemplateUtils.processTemplateIntoString(template, model);emailService.sendHtmlMail(receiveEmail, subject, templateHtml); }Test public void emailContailAttachmentTest() throws IOException, TemplateException, MessagingException {String receiveEmail hgmyzoutlook.com;String subject Spring Boot 发送包含附件的邮件测试;//添加动态数据替换模板里面的占位符SalaryVO salaryVO new SalaryVO(1, 小王, 2, 9000.00, 350.06, 280.05, 350.00, 7806.00);Template template freeMarkerConfigurer.getConfiguration().getTemplate(email.html);//将模板文件及数据渲染完成之后转换为html字符串MapString, Object model new HashMap();model.put(salary, salaryVO);String templateHtml FreeMarkerTemplateUtils.processTemplateIntoString(template, model);ListString fileList new ArrayList();fileList.add(F:\\邮件测试.docx);fileList.add(F:\\5.png);fileList.add(F:\\db.jpg);emailService.sendAttachmentsMail(receiveEmail, subject, templateHtml, fileList); } 7、效果截图 简单文版邮件                 html文件                 包含附件的邮件                 Gitee地址https://gitee.com/hgm1989/springboot-email.git
http://wiki.neutronadmin.com/news/95714/

相关文章:

  • 北京公司网站设计做地税电子签章的网站
  • 网站搭建商上海wordpress 翻译插件
  • 网站开发项目进度安排网站制作方案专业乐云seo
  • 网站面包屑导航设计特点国外网站为啥速度慢
  • 小说主角重生之后做网站ai画作拍卖在上海拍出110万高价
  • 泰安网网站建设天河电子商务网站建设
  • 网站开发运营费用网站弹窗广告怎么做
  • 中国建设招聘信息网站如何优化网站信息架构
  • 建站公司兴田德润好不好临沂网站建设有哪些
  • 天津建设注册执业中心网站效果图制作步骤
  • 国外美容网站设计一套企业网站设计报价
  • html在线记账网站模板湖北专业网站建设产品介绍
  • 合肥做网站的企业做网站需要先学什么
  • 西安淘宝网站建设公司排名栾川有做网站的吗
  • 做淘宝网站需要多少钱个人网站做音乐网要备文化
  • 上海做网站的公司电话上海买二手房做哪个网站好
  • 彩票网站开发制作平台软件wordpress head文件夹
  • 郓城网站建设费用织梦做中英文网站详细步骤
  • 深圳市城乡住房和建设局网站首页建设信息网的网站或平台登陆
  • 百度有哪些网站可免费做软件推广wordpress内存高
  • 青岛网站建设莫道网络wordpress 首页
  • jq网站登录记住密码怎么做宁波商城网站建设
  • 网站同时做竞价和优化可以建行网站用户名是什么
  • 企业营销型网站推广方法昆明做公司官网的公司
  • 网站购买流程动画片是怎么制作出来的
  • 珠海营销营网站建设射击官网
  • 网站开发搭建成都网站建设服务
  • 哪个网站能买到做披萨的芝士正宗wild合成版是哪个网站做的
  • 奖券世界推广网站wordpress edd支付宝
  • 西安自助建站系统别人用我的备案信息做网站