赤青1

那些我们丢失的美好!是我们永远的遗憾与记忆

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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>","");

 

 

posted on 2019-10-12 02:18  赤青1  阅读(572)  评论(0编辑  收藏  举报