线上页面代码模板

公众号兑换卡密

body, div, p, ul, li, a {

margin: 0;

padding: 0;

list-style: none;

text-decoration: none;

}

.wrap {

width: 750px;

height: 100%;

margin: 0 auto;

}

nav {

font-weight: 700;

padding: 20px 10px;

box-sizing: border-box;

background: #f9f9f9;

}

.nav-title {

margin: 0 0 20px;

}

.nav-content, .nav-end, .card-time {

font-size: 15px;

line-height: 30px;

}

.nav-tel {

color: #ff143f;

}

.list {

width: 750px;

margin: 20px 0;

}

.list ul {

width: 100%;

height: 36px;

font-size: 13px;

display: flex;

align-items: center;

/* justify-content: space-around; */

background: #e4e4e4;

border-radius: 8px 8px 0 0;

}

.list .list-ul {

background: #fff;

border-radius: 0;

height: 52px;

line-height: 52px;

background: #f9f9f9;

}

.list .list-ul li {

font-size: 12px;

}

/*产品名称*/

.goodsName {

text-align: center;

width: 150px;

padding-left: 6px;

}

.goodsName-li{

width: 150px;

text-align: center;

}

.orderNo {

text-align: center;

width: 175px;

}

.orderNo-li {

text-align: center;

width: 175px;

}

.facePrice {

text-align: right;

width: 75px;

}

.facePrice-li{

width: 75px;

text-align: center;

}

.cardNo {

text-align: center;

width: 150px;

}

.cardNo-li {

text-align: center;

width:150px;

}

.cardPwd {

text-align: center;

width: 75px;

}

.cardPwd-li {

text-align: center;

width: 75px;

}

.cardDate{

text-align:center; width: 125px;

}

尊敬的用户您好:

以下是您在【资和信签纸贺】公众号兑换的电子卡劵的卡号、卡密及有效期,点击电子卡名称可查看该电子卡

的使用说明,请在有效期限内使用您的各项卡劵。

如礼品卡兑换过程中有任何疑问,请拨打客服电话 95159 。感谢您的使用!

发卡日期:

  • 名称
  • 订单号
  • 金额
  • 卡号
  • 密码
  • 卡劵有效期

--后期所以css样式基于模板进行修改就非常简单,不用修改java程序代码

import cn.hutool.extra.mail.MailUtil;

import org.dom4j.*;

import org.dom4j.io.SAXReader;

import org.dom4j.io.XMLWriter;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.core.io.Resource;

import org.springframework.core.io.ResourceLoader;

import org.springframework.stereotype.Service;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.text.SimpleDateFormat;

import java.util.*;

/**

* @Author: SimonHu

* @Date: 2020/11/5 8:59

* @Description:

*/

@Service

public class SendHTMLMail {

private static final Logger log = LoggerFactory.getLogger(SendHTMLMail.class);

@Autowired

private ResourceLoader resourceLoader;

public static void main(String[] args) {

List list = new ArrayList();

Map map = new HashMap();

map.put("cardNo", "11111");

map.put("cardPwd", "11111");

Map map2 = new HashMap();

map2.put("cardNo", "http://www.baidu.com");

map2.put("cardPwd", "11111");

list.add(map);

list.add(map2);

SendHTMLMail sendHTMLMail = new SendHTMLMail();

sendHTMLMail.sendSimpleMail("8771014@qq.com", "10001", list);

}

/**

* @param sendMail

* @param orderNo

* @param sendJson

* @return void

* @Description:发送邮件

* @Author:SimonHu

* @Date: 2020/11/5 10:25

*/

public void sendSimpleMail(String sendMail, String orderNo, List sendJson) {

SAXReader reader = new SAXReader();

Document document = null;

FileWriter fwriter = null;

XMLWriter writer = null;

FileReader in = null;

try {

//获取模板html文档

Resource resource = resourceLoader.getResource("classpath:mail/mailTemple.html");

document = reader.read(resource.getInputStream());

Element root = document.getRootElement();

//获取id为time的节点。

Element time = getNodes(root, "id", "time");

Element tableHead = getNodes(root, "id", "table-head");

//设置发卡日期

time.setText(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));

Element tabElement = this.tableDocument(orderNo, sendJson);

if (tabElement != null) {

tableHead.appendContent(tabElement);

}

//保存到临时文件

fwriter = new FileWriter("classpath:temp.html");

writer = new XMLWriter(fwriter);

writer.write(document);

writer.flush();

//读取临时文件,并把html数据写入到字符串str中,通过邮箱工具发送

in = new FileReader("classpath:temp.html");

char[] buff = new char[1024 * 10];

in.read(buff);

String str = new String(buff);

log.info("================开始发送邮件======================");

MailUtil.send(sendMail, "【签纸贺】公众号兑换卡密", str.toString(), true);

log.info("================邮件发送完成======================");

} catch (Exception e) {

log.error("------sendSimpleMail-----", e);

} finally {

//关闭流

if (null != in) {

try {

in.close();

} catch (IOException e) {

e.printStackTrace();

}

}

if (null != writer) {

try {

writer.close();

} catch (IOException e) {

e.printStackTrace();

}

}

if (null != fwriter) {

try {

fwriter.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

/**

* @param orderNo

* @param sendJson

* @return java.lang.String

* @Description:获取table数据

* @Author:SimonHu

* @Date: 2020/11/5 9:32

*/

public Element tableDocument(String orderNo, List sendJson) {

StringBuffer eamilContext = new StringBuffer();

if (sendJson != null && !sendJson.isEmpty()) {

for (Map map : sendJson) {

eamilContext.append("

  • .append(map.get("goodsId")).append("\" style=\"color:#007eff;\">")

    .append(map.get("goodsName"))

    .append("

  • ").append(orderNo)

    .append("

  • ")

    .append(map.get("facePrice"));

    if (String.valueOf(map.get("cardNo")).indexOf("http") == -1) {

    eamilContext.append("

  • ").append(map.get("cardNo"));

    } else {

    eamilContext.append("

  • 去使用");

    }

    eamilContext.append("

  • ")

    .append(map.get("cardPwd"))

    .append("

  • ").append(map.get("expireTime")).append("

");

}

}

String htmlStr = "

" + eamilContext.toString() + "

";

try {

Document document = DocumentHelper.parseText(htmlStr);

return document.getRootElement();

} catch (DocumentException e) {

log.error(e.getMessage());

}

return null;

}

/**

* 方法描述:递归遍历子节点,根据属性名和属性值,找到对应属性名和属性值的那个子孙节点。

*

* @param node 要进行子节点遍历的节点

* @param attrName 属性名

* @param attrValue 属性值

* @return 返回对应的节点或null

*/

public Element getNodes(Element node, String attrName, String attrValue) {

// 当前节点的所有属性

final List listAttr = node.attributes();

// 遍历当前节点的所有属性

for (final Attribute attr : listAttr) {

// 属性名称

final String name = attr.getName();

// 属性的值

final String value = attr.getValue();

// System.out.println("属性名称:" + name + "---->属性值:" + value);

if (attrName.equals(name) && attrValue.equals(value)) {

return node;

}

}

// 递归遍历当前节点所有的子节点

// 所有一级子节点的list

final List listElement = node.elements();

//遍历所有一级子节点

for (Element e : listElement) {

Element temp = getNodes(e, attrName, attrValue);

// 递归

if (temp != null) {

return temp;

}

;

}

return null;

}

}

java html邮件_java发送html模板邮件相关推荐

  1. Android Java使用JavaMail API发送和接收邮件的代码示例

    JavaMail是Oracle甲骨文开发的Java邮件类API,支持多种邮件协议,这里我们就来看一下Java使用JavaMail API发送和接收邮件的代码示例 使用Javamail发送邮件,必需的j ...

  2. word合并邮件无法发送html,Word邮件合并批量发送带附件的邮件

    应张老师的需求,修改制作了一个可以批量发送带附件的电子邮件VBA. 目的:给N多人发送电子邮件,而不是抄送模式,并带有对方的称谓. 实现: 用到Word的邮件合并功能,以及调用Outlook发送邮件. ...

  3. php 实现邮件定时发送,PHP实现邮件的自动发送

    这样就可以实现邮件的发送了.结果如下: 如果要实现自动发送邮件的话,那么程序必须能自动的运行.程序在后台自动运行的代码如下:<?php ignore_user_abort(); // 后台运行 ...

  4. java exchange发邮件_java发送exchange邮件问题

    /** * 发送邀请 * @param cycleModel*/ protected voidsendEmail(CycleMailModel cycleModel) { Properties pro ...

  5. java发送qq邮箱_Java 发送QQ邮箱邮件

    如果需要提供用户名和密码给e-mail服务器来达到用户认证的目的,你可以通过如下设置来完成: props.put("mail.smtp.auth", "true" ...

  6. java如何接收邮件_java Exchange服务接收邮件

    标签:/** serverName 接收邮件地址 user 用户信息 pwd 密码 path 邮件临时储存路径 max 每次接收邮件的最大数量 **/ public int receive(Strin ...

  7. java 比特位_java发送比特位

    ...支持.第二个月,Pokkst对CC实施了一项新功能,该功能使人们可以通过短信发送比特币现金. Pokkst还以其在Tipbitcoin.cash平台上的工作而闻名,该工具使任何人都可以使用比特币 ...

  8. python发送html格式邮件,python 发送html格式邮件到qq(示例代码)

    #-*- coding: utf-8 -*- __author__ = 'Alon' __date__ = '2017/8/14 18:38' importsys reload(sys) sys.se ...

  9. java论坛短信息_JAVA发送短信

    1.[代码]JAVA发送短信 这几天,正好项目的间歇期,就研究了JAVA语言发送手机,呵呵,小有心得,做个笔记: JAVA发送手机短信,流传有几种方法:(1)使用webservice接口发送手机短信, ...

  10. java okhttp3 使用_Java发送http请求方法之OkHttp3

    1.前言 适用于Android开发和Web开发. 2.依赖 com.squareup.okhttp3 okhttp 3.3.0 3.Get请求 String url = "https://w ...

最新文章

  1. 重磅!这个 GitHub 汇总了 300 道 Python 面试题!
  2. 动态添加组件_使用vue.js的动态组件模板
  3. octave进行积分运算
  4. pythonの鉴黄之路(一)——YCbCr简易版鉴黄脚本
  5. 中国企业2017年数据_根据数据,2017年最好的免费在线课程
  6. python里氏替换原则_php设计模式的六大原则(三):里氏替换原则
  7. HTML5学习笔记(二):HTML基础学习之二
  8. Sound Grinder Pro for Mac(音频批量编辑转换工具)
  9. pydub mp3转wav
  10. HTML5学习系列之表单与文件
  11. WPF入门教程系列(4)
  12. 云服务器怎么设置成代理服务器?
  13. 基因表达式编程(GEP)自学 第【3】天 Python 实现
  14. -什么样的网站能赚钱
  15. iastora怎么改成ahci_WIN7系统硬盘IDE模式转AHCI模式
  16. 辗转相除法(欧几里得算法)
  17. 华为od统一考试B卷【跳房子2】Python 实现
  18. 恒源云(Gpushare)_【存储优化】/hy-tmp可以扩/缩容啦
  19. 云计算 第三章 Amazon云计算AWS
  20. win10怎样让当前用户获得管理员权限

热门文章

  1. Android 截屏监听分享
  2. Linux搭建局域网邮箱服务器,菜鸟搭建开源的局域网邮件服务器-windows linux均适用...
  3. java 系统找不到路径_java IOException:系统找不到指定的路径
  4. 似乎可以破解软件代码
  5. 罗斯蒙特8712ESR1A1N0M4流量变送器
  6. CFD:用软件完成流体仿真分析(step1)
  7. 微信小程序上传图片失败总结
  8. Visio自制直角箭头
  9. html限制视频上传大小,视频格式大小要求
  10. SpringCloud微服务实战—翟永超 读书笔记