Search in sources :

Example 1 with MailDetail

use of com.zyd.blog.business.entity.MailDetail in project OneBlog by zhangyd-c.

the class MailServiceImpl method sendToAdmin.

/**
 * 发送到管理员的评论通知
 *
 * @param comment
 */
@Override
@Async
public void sendToAdmin(Comment comment) {
    Map config = configService.getConfigs();
    Template template = templateService.getTemplate(TemplateKeyEnum.TM_NEW_COMMENT);
    String temXml = template.getRefValue();
    Map<String, Object> map = new HashMap<>(2);
    map.put("comment", comment);
    map.put("config", config);
    String mailContext = FreeMarkerUtil.template2String(temXml, map, true);
    String adminEmail = (String) config.get("authorEmail");
    if (StringUtils.isEmpty(adminEmail)) {
        log.warn("[sendToAdmin]邮件发送失败!未指定系统管理员的邮箱地址");
        return;
    }
    adminEmail = (adminEmail.contains("#") ? adminEmail.replace("#", "@") : adminEmail);
    MailDetail mailDetail = new MailDetail("有新的评论消息", adminEmail, (String) config.get("authorName"), mailContext);
    send(mailDetail);
}
Also used : HashMap(java.util.HashMap) MailDetail(com.zyd.blog.business.entity.MailDetail) HashMap(java.util.HashMap) Map(java.util.Map) Template(com.zyd.blog.business.entity.Template) Async(org.springframework.scheduling.annotation.Async)

Example 2 with MailDetail

use of com.zyd.blog.business.entity.MailDetail in project OneBlog by zhangyd-c.

the class MailServiceImpl method send.

/**
 * 发送友情链接邮件通知
 *
 * @param link
 * @param keyEnum
 * @return
 */
@Override
@Async
public void send(Link link, TemplateKeyEnum keyEnum) {
    if (!StringUtils.isEmpty(link.getEmail())) {
        Map config = configService.getConfigs();
        Template template = templateService.getTemplate(keyEnum);
        String temXml = template.getRefValue();
        Map<String, Object> map = new HashMap<>(2);
        map.put("link", link);
        map.put("config", config);
        String mailContext = FreeMarkerUtil.template2String(temXml, map, true);
        MailDetail mailDetail = new MailDetail("友情链接操作通知", link.getEmail(), link.getName(), mailContext);
        send(mailDetail);
    }
    this.sendToAdmin(link);
}
Also used : HashMap(java.util.HashMap) MailDetail(com.zyd.blog.business.entity.MailDetail) HashMap(java.util.HashMap) Map(java.util.Map) Template(com.zyd.blog.business.entity.Template) Async(org.springframework.scheduling.annotation.Async)

Example 3 with MailDetail

use of com.zyd.blog.business.entity.MailDetail in project OneBlog by zhangyd-c.

the class MailServiceImpl method sendToAdmin.

/**
 * 发送到管理员的友链操作通知
 *
 * @param link
 */
@Override
@Async
public void sendToAdmin(Link link) {
    Map config = configService.getConfigs();
    Template template = templateService.getTemplate(TemplateKeyEnum.TM_LINKS_TO_ADMIN);
    String temXml = template.getRefValue();
    Map<String, Object> map = new HashMap<>(1);
    map.put("link", link);
    String mailContext = FreeMarkerUtil.template2String(temXml, map, true);
    String adminEmail = (String) config.get(ConfigKeyEnum.AUTHOR_EMAIL.getKey());
    if (StringUtils.isEmpty(adminEmail)) {
        log.warn("[sendToAdmin]邮件发送失败!未指定系统管理员的邮箱地址");
        return;
    }
    adminEmail = (adminEmail.contains("#") ? adminEmail.replace("#", "@") : adminEmail);
    MailDetail mailDetail = new MailDetail("有新的友链消息", adminEmail, (String) config.get(ConfigKeyEnum.AUTHOR_NAME.getKey()), mailContext);
    send(mailDetail);
}
Also used : HashMap(java.util.HashMap) MailDetail(com.zyd.blog.business.entity.MailDetail) HashMap(java.util.HashMap) Map(java.util.Map) Template(com.zyd.blog.business.entity.Template) Async(org.springframework.scheduling.annotation.Async)

Example 4 with MailDetail

use of com.zyd.blog.business.entity.MailDetail in project OneBlog by zhangyd-c.

the class MailServiceImpl method send.

/**
 * 发送评论邮件通知
 *
 * @param comment
 * @param keyEnum
 * @param audit
 * @return
 */
@Override
@Async
public void send(Comment comment, TemplateKeyEnum keyEnum, boolean audit) {
    if (comment == null || StringUtils.isEmpty(comment.getEmail())) {
        this.sendToAdmin(comment);
        return;
    }
    Map config = configService.getConfigs();
    Template template = templateService.getTemplate(keyEnum);
    String temXml = template.getRefValue();
    Map<String, Object> map = new HashMap<>(2);
    map.put("comment", comment);
    map.put("config", config);
    String mailContext = FreeMarkerUtil.template2String(temXml, map, true);
    String subject = "评论回复通知";
    if (audit) {
        subject = "评论审核结果通知";
    }
    MailDetail mailDetail = new MailDetail(subject, comment.getEmail(), comment.getNickname(), mailContext);
    send(mailDetail);
    if (!audit) {
        this.sendToAdmin(comment);
    }
}
Also used : HashMap(java.util.HashMap) MailDetail(com.zyd.blog.business.entity.MailDetail) HashMap(java.util.HashMap) Map(java.util.Map) Template(com.zyd.blog.business.entity.Template) Async(org.springframework.scheduling.annotation.Async)

Aggregations

MailDetail (com.zyd.blog.business.entity.MailDetail)4 Template (com.zyd.blog.business.entity.Template)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Async (org.springframework.scheduling.annotation.Async)4