项目中碰到的简单的邮件发送,我把一些参数信息放在mail.properties文件里面,下面就是文件内容读取
public static Map getSystemMailCount(){
Map map=new HashMap();
InputStream inputStream = null;
inputStream =new MailUtil().getClass().getClassLoader().getResourceAsStream("mailConfig.properties");
Properties prop=new Properties();
try {
prop.load(inputStream);
String mailAcount=prop.get("mailAcount").toString();
String mailPwd=prop.get("mailPwd").toString();
String mailSmtp=prop.get("mailSmtp").toString();
String mailType=prop.get("mailType").toString();
String httpUrl=prop.get("httpUrl").toString();
map.put("mailAcount", mailAcount);
map.put("mailPwd", mailPwd);
map.put("mailSmtp", mailSmtp);
map.put("mailType", mailType);
map.put("httpUrl", httpUrl);
} catch (IOException e) {
e.printStackTrace();
System.out.println("邮箱配置文件读取失败!");
}
return map;
}
代码比较粗劣 但是总归是能读取到数据 希望对大家有用如果大家有更好的操作方式欢迎交流