javaMail2种方式实现,并读取html格式邮件模板

本文介绍如何使用JavaMailAPI读取HTML邮件模板并发送。提供了邮件模板工具类和邮件发送类的代码示例,强调了通过模板方式发送不同内容的邮件以适应客户需求。请注意,示例中的邮箱地址已被替换,实际使用时需填写正确信息。
摘要由CSDN通过智能技术生成

首先是邮件模板的读取工具类

package gamutsoft.mail.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

public class ReadHTML {

	/**
	 * @param args
	 */
	//public static void main(String[] args) {
		// TODO Auto-generated method stub
	public static String reMailString(){
		//String info="";
		StringBuffer buff=new StringBuffer();
		InputStreamReader in=null;
		BufferedReader br=null;
		String path = System.getProperty("user.dir") + "/src/html/email2.html";
		File file=new File(path);
		try {
			in=new InputStreamReader(new FileInputStream(file));
			br=new BufferedReader(in);
			String line=null;
			while((line=br.readLine()) != null){
				//System.out.println(line);
				buff.append(line).append("\n");
			}
			
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(in!=null){
				try {
					in.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(br!=null){
				try {
					br.close();
				} c
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值