---
title: "java向properties文件传动态参数发送邮件"
author: "weistar"
date: "2013-10-11T15:04:26Z"
tags: []
categories: ["编程语言"]
slug: "java-properties"
draft: true
lastmod: "2013-10-11T15:04:26Z"
id: 1955245
url: "https://weistar.iteye.com/blog/1955245"
---

首先,需要helloFile.properties 文件,里面有 key-value 键值对.

如果需要换行,则在一行最后加上"\\",注意参数对应顺序,如{0}{1}...  
动态传参，具体细节相见MessageFormat.format(String,Object...),仔细看看这个方法。  
具体代码如下：  
pulibc static void main(Strings\[] args)  
{  
    Localle locale = Local.getDefault();  
    ResourceBundle bundle = ResourceBundle.getBundle("helloFile",locale);

    String value = bundle.getString("hello");  
    String format = MessageFormat.format(value,new Object\[]{"北京"});  
}

下附properties邮件正文：

```
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>找回密码</title>
</head>
<body>
亲爱的用户&nbsp;{0}：<br/>
&nbsp;&nbsp;您好！我们是XXX系统的工作人员！<br/>
&nbsp;&nbsp;感谢您对连锁门店管理系统的信赖和支持！<br/>
&nbsp;&nbsp;您在连锁门店管理系统注册的用户名是：{1}<br/>
&nbsp;&nbsp;您的邮箱地址是：{2}<br/>
&nbsp;&nbsp;请<a href="{3}">点击</a>或复制这个网址去重新设置您的密码(24小时之内有效)：<br/>
&nbsp;&nbsp;<a href="{4}">{5}</a><br/>
&nbsp;&nbsp;最后祝你生活愉快！
&nbsp;&nbsp;<img src="{6}" border="0"/><br/>
</body>
</html>
```