网站给用户发邮件的解决方案

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();
                    }

声明 :  以上参考核心思路即可,照搬必错!!!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一缕阳光直射你的心扉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值