1.给用户发邮件内容的定义
例如
事例模版文件:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
</head>
<body>
<div style="width: 1000px; font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 16px; padding: 30px;">
<table width="98%" border="0" cellpadding="0" cellspacing="0" style="background: #eee;">
<tr style="height: 60px; text-align: center; vertical-align: middle;">
<td style="text-align: left; padding-left: 10px;">
<img src="http://www.bigluobo.com/img/logo151019.png" height="25">
</td>
<td width="160"
style="font-size: 18px; font-weight: bold; font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777;">
大萝卜招聘
</td>
</tr>
</table>
<table width="98%" border="0" cellspacing="0" cellpadding="0" style="background: #fff; border: 10px solid #eee;">
<tr>
<td style="padding: 20px;">
<p style="font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 16px;">
您好:</p>
<p>
<span style="padding-left: 20px; line-height: 30px; font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 16px;">
有兔子推荐了合适的人才给企业,请登录大萝卜招聘,进入“简历管理”,进行查看。
</span>
</p>
<table width="100%" border="0" cellspacing="1" cellpadding="0" style="background: #ddd; line-height: 36px;">
<tr align="center">
<td style="background: #eee;font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 14px;">公司名</td>
<td style="background: #eee;font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 14px;">职位名</td>
<td style="background: #eee;font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 14px;">发布日期</td>
<td style="background: #eee;font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 14px;">应聘人</td>
<td style="background: #eee;font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 14px;">推荐人</td>
<td style="background: #eee;font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 14px;">推荐日期</td>
<td style="background: #eee;font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 14px;">实名/匿名</td>
</tr>
<tr align="center">
<td style="background: #fff;font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 14px;">%company_name%</td>
<td style="background: #fff;font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 14px;">%job_name%</td>
<td style="background: #fff;font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 14px;">%publish_date%</td>
<td style="background: #fff;font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 14px;">%candidate_name%</td>
<td style="background: #fff;font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 14px;">%referrer_name%</td>
<td style="background: #fff;font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 14px;">%recommend_date%</td>
<td style="background: #fff;font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 14px;">%anonymous%</td>
</tr>
</table>
<p>
<span style="padding-left: 20px; line-height: 30px; font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 16px;">
跟进人:%repName%
</span>
</p>
<p style="text-align: center;">
<a href="%url%" target="_blank"
style="text-decoration: none; display: inline-block; padding: 6px 12px; margin-bottom: 0; font-size: 16px; font-weight: 400; line-height: 1.42857143; text-align: center; white-space: nowrap; vertical-align: middle; -ms-touch-action: manipulation; touch-action: manipulation; cursor: pointer; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; background-image: none; border: 1px solid transparent; border-radius: 4px; color: #fff; background-color: #5cb85c; border-color: #4cae4c; width: 160px;">登录查看</a>
</p>
<p style="font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 12px;">
大萝卜招聘自动邮件,请勿回复。
</p>
</td>
</tr>
</table>
<table width="98%" border="0" cellpadding="0" cellspacing="0"
style="background: #eee;font-family: 'Hiragino Sans GB', 'microsoft yahei', Helvetica, Arial, sans-serif; color: #777; font-size: 14px;">
<tr style="text-align: center; height: 40px; vertical-align: middle;">
</tr>
</table>
</div>
</body>
</html>
方法:
先定义html文件的内容(样式+文字),再替换文字。
getContent方法
public String getContent(String templateName) {
StringBuffer result = new StringBuffer();
File file = new File(getServerRoot() + File.separator + MAIL_TEMPLATE_PATH + File.separator + templateName);
if (file.exists()) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String line = reader.readLine();
while (line != null) {
result.append(line);
line = reader.readLine();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
return "";
} catch (IOException e) {
e.printStackTrace();
return "";
} finally {
if (reader != null) {
try {
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
} else {
logger.error("未找到该模版文件");
}
return result.toString();
}
完成调用
String content = mailTemplate.getContent("new_recommend_notify.html");
if (!StringUtils.isEmpty(content)) {
content = content.replaceAll("%company_name%", saved.getJob().getCompany().getName());
content = content.replaceAll("%job_name%", saved.getJob().getName());
content = content.replaceAll("%publish_date%", DateUtils.formatDate(saved.getJob().getPublishDate(), "yyyy-MM-dd"));
content = content.replaceAll("%candidate_name%", saved.getCv().getName());
content = content.replaceAll("%referrer_name%", saved.getUser().getName());
content = content.replaceAll("%recommend_date%", DateUtils.formatDate(saved.getRecommendDate(), "yyyy-MM-dd"));
content = content.replaceAll("%anonymous%", saved.getIsAnonymous() ? "匿名推荐" : "实名推荐");
content = content.replaceAll("%repName%", userDao.find(job.getCompany().getRepId()).getName());//获得对接人的name值
final String emailContent = content.replaceAll("%url%", url.toString());
new Thread(new Runnable() {
@Override
public void run() {
try {
SendCloud.sendByHTTP(null, title, emailContent);
} catch (Exception e) {
logger.error("发送职位推荐通知邮件失败:", e);
}
}
}).start();
}
声明 : 以上参考核心思路即可,照搬必错!!!