mirror of https://github.com/halo-dev/halo
				
				
				
			feat: support custom email templates. (#691)
							parent
							
								
									8eac5716f1
								
							
						
					
					
						commit
						c847bef498
					
				| 
						 | 
				
			
			@ -48,7 +48,9 @@ public class CommentEventListener {
 | 
			
		|||
 | 
			
		||||
    private final UserService userService;
 | 
			
		||||
 | 
			
		||||
    public CommentEventListener(MailService mailService, OptionService optionService, PostCommentService postCommentService, SheetCommentService sheetCommentService, JournalCommentService journalCommentService, PostService postService, SheetService sheetService, JournalService journalService, UserService userService) {
 | 
			
		||||
    private final ThemeService themeService;
 | 
			
		||||
 | 
			
		||||
    public CommentEventListener(MailService mailService, OptionService optionService, PostCommentService postCommentService, SheetCommentService sheetCommentService, JournalCommentService journalCommentService, PostService postService, SheetService sheetService, JournalService journalService, UserService userService, ThemeService themeService) {
 | 
			
		||||
        this.mailService = mailService;
 | 
			
		||||
        this.optionService = optionService;
 | 
			
		||||
        this.postCommentService = postCommentService;
 | 
			
		||||
| 
						 | 
				
			
			@ -58,6 +60,7 @@ public class CommentEventListener {
 | 
			
		|||
        this.sheetService = sheetService;
 | 
			
		||||
        this.journalService = journalService;
 | 
			
		||||
        this.userService = userService;
 | 
			
		||||
        this.themeService = themeService;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			@ -90,8 +93,8 @@ public class CommentEventListener {
 | 
			
		|||
 | 
			
		||||
            BasePostMinimalDTO post = postService.convertToMinimal(postService.getById(postComment.getPostId()));
 | 
			
		||||
 | 
			
		||||
            data.put("url", post.getFullPath());
 | 
			
		||||
            data.put("page", post.getTitle());
 | 
			
		||||
            data.put("pageFullPath", post.getFullPath());
 | 
			
		||||
            data.put("pageTitle", post.getTitle());
 | 
			
		||||
            data.put("author", postComment.getAuthor());
 | 
			
		||||
            data.put("content", postComment.getContent());
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -106,8 +109,8 @@ public class CommentEventListener {
 | 
			
		|||
 | 
			
		||||
            BasePostMinimalDTO sheet = sheetService.convertToMinimal(sheetService.getById(sheetComment.getPostId()));
 | 
			
		||||
 | 
			
		||||
            data.put("url", sheet.getFullPath());
 | 
			
		||||
            data.put("page", sheet.getTitle());
 | 
			
		||||
            data.put("pageFullPath", sheet.getFullPath());
 | 
			
		||||
            data.put("pageTitle", sheet.getTitle());
 | 
			
		||||
            data.put("author", sheetComment.getAuthor());
 | 
			
		||||
            data.put("content", sheetComment.getContent());
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -124,15 +127,21 @@ public class CommentEventListener {
 | 
			
		|||
            StrBuilder url = new StrBuilder(optionService.getBlogBaseUrl())
 | 
			
		||||
                .append("/")
 | 
			
		||||
                .append(optionService.getJournalsPrefix());
 | 
			
		||||
            data.put("url", url.toString());
 | 
			
		||||
            data.put("page", journal.getCreateTime());
 | 
			
		||||
            data.put("pageFullPath", url.toString());
 | 
			
		||||
            data.put("pageTitle", journal.getCreateTime());
 | 
			
		||||
            data.put("author", journalComment.getAuthor());
 | 
			
		||||
            data.put("content", journalComment.getContent());
 | 
			
		||||
 | 
			
		||||
            subject.append("您的博客日志有了新的评论");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        mailService.sendTemplateMail(user.getEmail(), subject.toString(), data, "common/mail_template/mail_notice.ftl");
 | 
			
		||||
        String template = "common/mail_template/mail_notice.ftl";
 | 
			
		||||
 | 
			
		||||
        if (themeService.templateExists("mail_template/mail_notice.ftl")) {
 | 
			
		||||
            template = themeService.renderWithSuffix("mail_template/mail_notice");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        mailService.sendTemplateMail(user.getEmail(), subject.toString(), data, template);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			@ -178,8 +187,8 @@ public class CommentEventListener {
 | 
			
		|||
 | 
			
		||||
            BasePostMinimalDTO post = postService.convertToMinimal(postService.getById(postComment.getPostId()));
 | 
			
		||||
 | 
			
		||||
            data.put("url", post.getFullPath());
 | 
			
		||||
            data.put("page", post.getTitle());
 | 
			
		||||
            data.put("pageFullPath", post.getFullPath());
 | 
			
		||||
            data.put("pageTitle", post.getTitle());
 | 
			
		||||
            data.put("baseAuthor", baseComment.getAuthor());
 | 
			
		||||
            data.put("baseContent", baseComment.getContent());
 | 
			
		||||
            data.put("replyAuthor", postComment.getAuthor());
 | 
			
		||||
| 
						 | 
				
			
			@ -208,8 +217,8 @@ public class CommentEventListener {
 | 
			
		|||
 | 
			
		||||
            BasePostMinimalDTO sheet = sheetService.convertToMinimal(sheetService.getById(sheetComment.getPostId()));
 | 
			
		||||
 | 
			
		||||
            data.put("url", sheet.getFullPath());
 | 
			
		||||
            data.put("page", sheet.getTitle());
 | 
			
		||||
            data.put("pageFullPath", sheet.getFullPath());
 | 
			
		||||
            data.put("pageTitle", sheet.getTitle());
 | 
			
		||||
            data.put("baseAuthor", baseComment.getAuthor());
 | 
			
		||||
            data.put("baseContent", baseComment.getContent());
 | 
			
		||||
            data.put("replyAuthor", sheetComment.getAuthor());
 | 
			
		||||
| 
						 | 
				
			
			@ -240,8 +249,8 @@ public class CommentEventListener {
 | 
			
		|||
            StrBuilder url = new StrBuilder(optionService.getBlogBaseUrl())
 | 
			
		||||
                .append("/")
 | 
			
		||||
                .append(optionService.getJournalsPrefix());
 | 
			
		||||
            data.put("url", url);
 | 
			
		||||
            data.put("page", journal.getContent());
 | 
			
		||||
            data.put("pageFullPath", url);
 | 
			
		||||
            data.put("pageTitle", journal.getContent());
 | 
			
		||||
            data.put("baseAuthor", baseComment.getAuthor());
 | 
			
		||||
            data.put("baseContent", baseComment.getContent());
 | 
			
		||||
            data.put("replyAuthor", journalComment.getAuthor());
 | 
			
		||||
| 
						 | 
				
			
			@ -253,6 +262,12 @@ public class CommentEventListener {
 | 
			
		|||
                .append("有了新的评论。");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        mailService.sendTemplateMail(baseAuthorEmail, subject.toString(), data, "common/mail_template/mail_reply.ftl");
 | 
			
		||||
        String template = "common/mail_template/mail_reply.ftl";
 | 
			
		||||
 | 
			
		||||
        if (themeService.templateExists("mail_template/mail_reply.ftl")) {
 | 
			
		||||
            template = themeService.renderWithSuffix("mail_template/mail_reply");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        mailService.sendTemplateMail(baseAuthorEmail, subject.toString(), data, template);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,13 +6,13 @@
 | 
			
		|||
            </h1>
 | 
			
		||||
            <div class="emailtext" style="background:#fff;padding:20px 32px 40px;">
 | 
			
		||||
                <p style="color: #6e6e6e;font-size:13px;line-height:24px;">${user.nickname!}, 您好!</p>
 | 
			
		||||
                <p style="color: #6e6e6e;font-size:13px;line-height:24px;">有访客在《${page!}》留言:</p>
 | 
			
		||||
                <p style="color: #6e6e6e;font-size:13px;line-height:24px;">有访客在《${pageTitle!}》留言:</p>
 | 
			
		||||
                    <br />
 | 
			
		||||
                <p style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0">
 | 
			
		||||
                ${author!}:${content!}
 | 
			
		||||
                </p>
 | 
			
		||||
                <br />
 | 
			
		||||
                <p style="color: #6e6e6e;font-size:13px;line-height:24px;">您可以点击<a href="${url!}">查看完整内容</a></p>
 | 
			
		||||
                <p style="color: #6e6e6e;font-size:13px;line-height:24px;">您可以点击<a href="${pageFullPath!}">查看完整内容</a></p>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,14 +7,14 @@
 | 
			
		|||
            <div class="emailtext" style="background:#fff;padding:20px 32px 40px;">
 | 
			
		||||
 | 
			
		||||
                <p style="color: #6e6e6e;font-size:13px;line-height:24px;">${baseAuthor!}, 您好!</p>
 | 
			
		||||
                <p style="color: #6e6e6e;font-size:13px;line-height:24px;">您在《${page!}》的留言:
 | 
			
		||||
                <p style="color: #6e6e6e;font-size:13px;line-height:24px;">您在《${pageTitle!}》的留言:
 | 
			
		||||
                    <br />
 | 
			
		||||
                <p style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0">${baseContent!}</p>
 | 
			
		||||
                <p style="color: #6e6e6e;font-size:13px;line-height:24px;">${replyAuthor!} 给您的回复:
 | 
			
		||||
                    <br />
 | 
			
		||||
                <p style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0">${replyContent!}</p>
 | 
			
		||||
                <p style="color: #6e6e6e;font-size:13px;line-height:24px;">您可以点击
 | 
			
		||||
                    <a href="${url!}">查看完整内容</a>
 | 
			
		||||
                    <a href="${pageFullPath!}">查看完整内容</a>
 | 
			
		||||
                </p>
 | 
			
		||||
                <p style="color: #6e6e6e;font-size:13px;line-height:24px;">欢迎再度光临
 | 
			
		||||
                    <a href="${blog_url!}">${blog_title!}</a>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue