后台根据html邮件模板发送邮件

HTML邮件模板:

xxxxxxx

在线模板的方式:

String fileName = "http://localhost:8080/xxxxxxx.html";
URL url = new URL(fileName);
URLConnection uc = url.openConnection();
InputStream is = uc.getInputStream();
String str = "";
BufferedReader br = new BufferedReader(new InputStreamReader(is));
while (br.ready()) {
str += br.readLine() + "\n";
}
is.close();
System.out.println(str);

//使用replaceAll替换模板中的动态值  [###val###]

//通过邮箱工具类发送html邮件

https://www.cnblogs.com/yhm9/p/11642775.html

固定目录静态html模板方式:

String filePath="d:\\Dev\\Workspace\\ecology-itl\\ecology-itl\\WebContent\\registerEmail.html";

String str = "";
try{
String tempStr = "";
FileInputStream is = new FileInputStream(filePath);//读取模块文件
BufferedReader br = new BufferedReader(new InputStreamReader(is));
while ((tempStr = br.readLine()) != null) {
str = str + tempStr ;
is.close();
}
}catch (IOException e) {
e.printStackTrace();
}
//替换值

String filePath = "xxxxx";//模板地址
String str = "";
FileInputStream is = null;
BufferedReader br = null;
try {
String tempStr = "";
is = new FileInputStream(filePath);
br = new BufferedReader(new InputStreamReader(is));
while ((tempStr = br.readLine()) != null) {
str = str + tempStr;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
is.close();
}
}
// 替换值
str = str.replaceAll("###name###", 值);

//通过邮箱工具类发送html邮件

https://www.cnblogs.com/yhm9/p/11642775.html

获取DOM节点内容:

https://www.open-open.com/jsoup/load-document-from-url.htm    【Jsoup文档】

Document doc =Jsoup.connect(html模板地址).get().body().toString()
Element body = doc.body();
str=body.toString();

替换不需要的标签

str = str.replaceAll("<body>","");
str = str.replaceAll("</body>","");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

知青先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值