1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863
| @Service public class EmailServiceImpl { @Autowired private JavaMailSender mailSender;
@Autowired private ArticleMapper articleMapper;
@Autowired private CommentMapper commentMapper;
@Value("${spring.mail.username}") private String from;
@Value("${blog.frontend.url:http://localhost:3000}") private String frontendUrl;
@Async("asyncExecutor") public void sendVerificationCodeByLogin(String to, String code) { sendVerificationEmail(to, code, "登录", "您正在进行登录操作,请使用以下验证码完成登录。"); } @Async("asyncExecutor") public void sendVerificationCodeByRegister(String to, String code) { sendVerificationEmail(to, code, "注册", "欢迎注册云梦泽的个人博客!请使用以下验证码完成注册。"); } @Async("asyncExecutor") public void sendVerificationCodeByForgotPassword(String to, String code) { sendVerificationEmail(to, code, "重置密码", "您正在进行密码重置操作,请使用以下验证码完成密码重置。"); }
@Async("asyncExecutor") public void sendNewCommentNotification(String articleTitle, String commenterNickname, String commentContent, String articleUrl) { try { MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
helper.setFrom(from); helper.setTo(from); helper.setSubject("【云梦泽的个人博客】您收到了新评论");
String htmlContent = buildCommentNotificationHtml(articleTitle, commenterNickname, commentContent, articleUrl, "新评论"); helper.setText(htmlContent, true);
mailSender.send(message); } catch (MessagingException e) { e.printStackTrace(); } }
@Async("asyncExecutor") public void sendCommentReplyNotificationByEmail(String toEmail, String articleTitle, String replierNickname, String replyContent, String originalComment, String articleUrl) { try { MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
helper.setFrom(from); helper.setTo(toEmail); helper.setSubject("【云梦泽的个人博客】您的评论收到了新回复");
String htmlContent = buildReplyNotificationHtml(articleTitle, replierNickname, replyContent, originalComment, articleUrl); helper.setText(htmlContent, true);
mailSender.send(message); } catch (MessagingException e) { e.printStackTrace(); } }
@Async("asyncExecutor") public void sendCommentNotificationByEmail(Comment comment) { try { String articleTitle = getArticleTitle(comment); String articleUrl = buildArticleUrl(comment);
if (comment.getRootId() != null && comment.getRootId() != -1L) { Comment parentComment = commentMapper.selectById(comment.getReplyToCommentId()); if (parentComment != null && StringUtils.hasText(parentComment.getEmail())) { if (!comment.getEmail().equalsIgnoreCase(parentComment.getEmail())) { sendCommentReplyNotificationByEmail( parentComment.getEmail(), articleTitle, comment.getNickname(), comment.getContent(), parentComment.getContent(), articleUrl ); } } }
if (!comment.getEmail().equalsIgnoreCase(SystemConstants.BLOGGER_EMAIL)) { sendNewCommentNotification( articleTitle, comment.getNickname(), comment.getContent(), articleUrl ); } } catch (Exception e) { e.printStackTrace(); } }
@Async("asyncExecutor") public void sendSensitiveWordNotification(Comment comment) { try { String articleTitle = getArticleTitle(comment); String articleUrl = buildArticleUrl(comment);
Map<String, String> sensitiveWordsWithSource = SensitiveUtil.findSensitiveWordsWithSource(comment.getContent()); java.util.List<String> sensitiveWords = new java.util.ArrayList<>(sensitiveWordsWithSource.keySet()); sendSensitiveWordNotificationToUser( comment.getEmail(), comment.getNickname(), comment.getContent(), articleTitle, articleUrl, sensitiveWords );
sendSensitiveWordNotificationToAdmin( comment.getNickname(), comment.getEmail(), comment.getContent(), articleTitle, articleUrl, sensitiveWordsWithSource ); } catch (Exception e) { e.printStackTrace(); } }
@Async("asyncExecutor") public void sendCommentApprovedNotification(Comment comment) { try { String articleTitle = getArticleTitle(comment); String articleUrl = buildArticleUrl(comment);
MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
helper.setFrom(from); helper.setTo(comment.getEmail()); helper.setSubject("【云梦泽的个人博客】您的评论已通过审核");
String htmlContent = buildCommentApprovedNotificationHtml( comment.getNickname(), comment.getContent(), articleTitle, articleUrl ); helper.setText(htmlContent, true);
mailSender.send(message); } catch (MessagingException e) { e.printStackTrace(); } }
@Async("asyncExecutor") public void sendCommentRejectedNotification(Comment comment) { try { String articleTitle = getArticleTitle(comment); String articleUrl = buildArticleUrl(comment);
MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
helper.setFrom(from); helper.setTo(comment.getEmail()); helper.setSubject("【云梦泽的个人博客】您的评论未通过审核");
String htmlContent = buildCommentRejectedNotificationHtml( comment.getNickname(), comment.getContent(), articleTitle, articleUrl ); helper.setText(htmlContent, true);
mailSender.send(message); } catch (MessagingException e) { e.printStackTrace(); } }
private String getArticleTitle(Comment comment) { String type = comment.getType(); if (SystemConstants.COMMENT_TYPE_ARTICLE.equals(type) && comment.getArticleId() != null) { Article article = articleMapper.selectById(comment.getArticleId()); return article != null ? article.getTitle() : "未知文章"; } else if (SystemConstants.COMMENT_TYPE_LINK.equals(type)) { return "友链评论"; } else if (SystemConstants.COMMENT_TYPE_MESSAGE.equals(type)) { return "留言板"; } return "评论"; }
private String buildArticleUrl(Comment comment) { String type = comment.getType(); if (SystemConstants.COMMENT_TYPE_ARTICLE.equals(type) && comment.getArticleId() != null) { return frontendUrl + "/post/" + comment.getArticleId(); } else if (SystemConstants.COMMENT_TYPE_LINK.equals(type)) { return frontendUrl + "/links"; } else if (SystemConstants.COMMENT_TYPE_MESSAGE.equals(type)) { return frontendUrl + "/messages"; } return frontendUrl; }
private void sendVerificationEmail(String to, String code, String scene, String description) { try { MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8"); helper.setFrom(from); helper.setTo(to); helper.setSubject("【云梦泽的个人博客】" + scene + "验证码"); String htmlContent = buildEmailHtml(code, scene, description); helper.setText(htmlContent, true); mailSender.send(message); } catch (MessagingException e) { throw new RuntimeException("邮件发送失败", e); } }
private void sendSensitiveWordNotificationToUser(String toEmail, String nickname, String commentContent, String articleTitle, String articleUrl, java.util.List<String> sensitiveWords) { try { MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
helper.setFrom(from); helper.setTo(toEmail); helper.setSubject("【云梦泽的个人博客】您的评论需要审核");
String htmlContent = buildSensitiveWordUserNotificationHtml(nickname, commentContent, articleTitle, articleUrl, sensitiveWords); helper.setText(htmlContent, true);
mailSender.send(message); } catch (MessagingException e) { e.printStackTrace(); } }
private void sendSensitiveWordNotificationToAdmin(String commenterNickname, String commenterEmail, String commentContent, String articleTitle, String articleUrl, java.util.Map<String, String> sensitiveWordsWithSource) { try { MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
helper.setFrom(from); helper.setTo(from); helper.setSubject("【云梦泽的个人博客】评论待审核 - 检测到敏感词");
String htmlContent = buildSensitiveWordAdminNotificationHtml(commenterNickname, commenterEmail, commentContent, articleTitle, articleUrl, sensitiveWordsWithSource); helper.setText(htmlContent, true);
mailSender.send(message); } catch (MessagingException e) { e.printStackTrace(); } }
private String buildEmailHtml(String code, String scene, String description) { String themeColor = getThemeColor(scene); String greeting = getGreeting(scene); return "<!DOCTYPE html>" + "<html>" + "<head>" + " <meta charset=\"UTF-8\">" + " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" + "</head>" + "<body style=\"margin: 0; padding: 0; background: linear-gradient(135deg, #a5dff9 0%, #008c9e 100%); font-family: 'Segoe UI', Arial, sans-serif;\">" + " <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"padding: 40px 20px;\">" + " <tr>" + " <td align=\"center\">" + " <table width=\"600\" cellpadding=\"0\" cellspacing=\"0\" style=\"background-color: #f5fffa; border-radius: 12px; box-shadow: 0 12px 15px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19); overflow: hidden;\">" + " <!-- 头部 -->" + " <tr>" + " <td style=\"background: rgb(125, 182, 191); padding: 40px 30px; text-align: center;\">" + " <h1 style=\"color: #2c3e50; margin: 0; font-size: 28px; font-weight: 600; letter-spacing: 1px;\">云梦泽的个人博客</h1>" + " <p style=\"color: #546e7a; margin: 10px 0 0 0; font-size: 14px;\">Cloud Dream Marsh Blog</p>" + " </td>" + " </tr>" + " <!-- 内容 -->" + " <tr>" + " <td style=\"padding: 50px 40px;\">" + " <h2 style=\"color: #3c4858; margin: 0 0 20px 0; font-size: 22px; font-weight: 600;\">" + greeting + "</h2>" + " <p style=\"color: #718096; line-height: 1.8; margin: 0 0 30px 0; font-size: 15px;\">" + " " + description + " </p>" + " <!-- 验证码区域 -->" + " <div style=\"background: linear-gradient(135deg, #f8f9fa 0%, #e8f4f8 100%); border-left: 4px solid " + themeColor + "; border-radius: 8px; padding: 30px; margin: 30px 0; text-align: center; box-shadow: 0 2px 8px rgba(48,169,222,0.1);\">" + " <p style=\"color: #718096; margin: 0 0 15px 0; font-size: 13px; text-transform: uppercase; letter-spacing: 1px;\">您的" + scene + "验证码</p>" + " <p style=\"color: " + themeColor + "; font-size: 36px; font-weight: bold; letter-spacing: 10px; margin: 0; font-family: 'Courier New', monospace;\">" + code + "</p>" + " </div>" + " <!-- 提示信息 -->" + " <div style=\"background-color: #fff8e1; border-left: 4px solid #ffc107; border-radius: 8px; padding: 20px; margin: 25px 0;\">" + " <p style=\"color: #3c4858; line-height: 1.8; margin: 0; font-size: 14px;\">" + " 验证码有效期为 <strong>5分钟</strong>,请尽快完成验证<br>" + " 请勿将验证码泄露给他人<br>" + " 如非本人操作,请忽略此邮件" + " </p>" + " </div>" + " </td>" + " </tr>" + " <!-- 底部 -->" + " <tr>" + " <td style=\"background: linear-gradient(135deg, #f8f9fa 0%, #eaecef 100%); padding: 30px; text-align: center; border-top: 1px solid #eaecef;\">" + " <p style=\"color: #718096; margin: 0 0 10px 0; font-size: 13px;\">" + " 此邮件由系统自动发送,请勿直接回复" + " </p>" + " <p style=\"color: #a7a9ad; margin: 0; font-size: 12px;\">" + " © " + LocalDate.now().getYear() + " 云梦泽的个人博客 · All rights reserved" + " </p>" + " </td>" + " </tr>" + " </table>" + " <!-- 额外提示 -->" + " <table width=\"600\" cellpadding=\"0\" cellspacing=\"0\" style=\"margin-top: 20px;\">" + " <tr>" + " <td style=\"text-align: center; padding: 10px;\">" + " <p style=\"color: rgba(255,255,255,0.9); margin: 0; font-size: 12px; text-shadow: 0 1px 2px rgba(0,0,0,0.1);\">" + " 如有疑问,请访问我们的网站或联系客服" + " </p>" + " </td>" + " </tr>" + " </table>" + " </td>" + " </tr>" + " </table>" + "</body>" + "</html>"; }
private String buildCommentNotificationHtml(String articleTitle, String commenterNickname, String commentContent, String articleUrl, String notificationType) { return "<!DOCTYPE html>" + "<html>" + "<head>" + " <meta charset=\"UTF-8\">" + " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" + "</head>" + "<body style=\"margin: 0; padding: 0; background: linear-gradient(135deg, #a5dff9 0%, #008c9e 100%); font-family: 'Segoe UI', Arial, sans-serif;\">" + " <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"padding: 40px 20px;\">" + " <tr>" + " <td align=\"center\">" + " <table width=\"600\" cellpadding=\"0\" cellspacing=\"0\" style=\"background-color: #f5fffa; border-radius: 12px; box-shadow: 0 12px 15px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19); overflow: hidden;\">" + " <!-- 头部 -->" + " <tr>" + " <td style=\"background: rgb(125, 182, 191); padding: 40px 30px; text-align: center;\">" + " <h1 style=\"color: #2c3e50; margin: 0; font-size: 28px; font-weight: 600; letter-spacing: 1px;\">云梦泽的个人博客</h1>" + " <p style=\"color: #546e7a; margin: 10px 0 0 0; font-size: 14px;\">评论通知</p>" + " </td>" + " </tr>" + " <!-- 内容 -->" + " <tr>" + " <td style=\"padding: 50px 40px;\">" + " <h2 style=\"color: #3c4858; margin: 0 0 20px 0; font-size: 22px; font-weight: 600;\">您收到了" + notificationType + "</h2>" + " <p style=\"color: #718096; line-height: 1.8; margin: 0 0 30px 0; font-size: 15px;\">" + " <strong>" + commenterNickname + "</strong> 在文章《<strong>" + articleTitle + "</strong>》中发表了评论。" + " </p>" + " <!-- 评论内容区域 -->" + " <div style=\"background: linear-gradient(135deg, #f8f9fa 0%, #e8f4f8 100%); border-left: 4px solid #30a9de; border-radius: 8px; padding: 25px; margin: 30px 0; box-shadow: 0 2px 8px rgba(48,169,222,0.1);\">" + " <p style=\"color: #718096; margin: 0 0 10px 0; font-size: 13px; text-transform: uppercase; letter-spacing: 1px;\">评论内容</p>" + " <p style=\"color: #3c4858; font-size: 15px; line-height: 1.8; margin: 0; word-wrap: break-word;\">" + commentContent + "</p>" + " </div>" + " <!-- 查看按钮 -->" + " <div style=\"text-align: center; margin: 30px 0;\">" + " <a href=\"" + articleUrl + "\" style=\"display: inline-block; background: linear-gradient(135deg, #30a9de 0%, #2196f3 100%); color: #ffffff; text-decoration: none; padding: 14px 40px; border-radius: 25px; font-size: 15px; font-weight: 600; box-shadow: 0 4px 15px rgba(48,169,222,0.3); transition: all 0.3s;\">查看评论</a>" + " </div>" + " </td>" + " </tr>" + " <!-- 底部 -->" + " <tr>" + " <td style=\"background: linear-gradient(135deg, #f8f9fa 0%, #eaecef 100%); padding: 30px; text-align: center; border-top: 1px solid #eaecef;\">" + " <p style=\"color: #718096; margin: 0 0 10px 0; font-size: 13px;\">" + " 此邮件由系统自动发送,请勿直接回复" + " </p>" + " <p style=\"color: #a7a9ad; margin: 0; font-size: 12px;\">" + " © " + LocalDate.now().getYear() + " 云梦泽的个人博客 · All rights reserved" + " </p>" + " </td>" + " </tr>" + " </table>" + " </td>" + " </tr>" + " </table>" + "</body>" + "</html>"; }
private String buildSensitiveWordUserNotificationHtml(String nickname, String commentContent, String articleTitle, String articleUrl, java.util.List<String> sensitiveWords) { StringBuilder sensitiveWordsHtml = new StringBuilder(); if (sensitiveWords != null && !sensitiveWords.isEmpty()) { for (String word : sensitiveWords) { sensitiveWordsHtml.append("<span style=\"display: inline-block; background-color: #ffebee; color: #d32f2f; padding: 4px 12px; margin: 4px; border-radius: 12px; font-size: 13px; font-weight: 600;\">") .append(word) .append("</span>"); } } return "<!DOCTYPE html>" + "<html>" + "<head>" + " <meta charset=\"UTF-8\">" + " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" + "</head>" + "<body style=\"margin: 0; padding: 0; background: linear-gradient(135deg, #a5dff9 0%, #008c9e 100%); font-family: 'Segoe UI', Arial, sans-serif;\">" + " <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"padding: 40px 20px;\">" + " <tr>" + " <td align=\"center\">" + " <table width=\"600\" cellpadding=\"0\" cellspacing=\"0\" style=\"background-color: #f5fffa; border-radius: 12px; box-shadow: 0 12px 15px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19); overflow: hidden;\">" + " <!-- 头部 -->" + " <tr>" + " <td style=\"background: rgb(255, 152, 0); padding: 40px 30px; text-align: center;\">" + " <h1 style=\"color: #ffffff; margin: 0; font-size: 28px; font-weight: 600; letter-spacing: 1px;\">云梦泽的个人博客</h1>" + " <p style=\"color: #fff3e0; margin: 10px 0 0 0; font-size: 14px;\">评论审核通知</p>" + " </td>" + " </tr>" + " <!-- 内容 -->" + " <tr>" + " <td style=\"padding: 50px 40px;\">" + " <h2 style=\"color: #3c4858; margin: 0 0 20px 0; font-size: 22px; font-weight: 600;\">您好," + nickname + "!</h2>" + " <p style=\"color: #718096; line-height: 1.8; margin: 0 0 30px 0; font-size: 15px;\">" + " 感谢您在《<strong>" + articleTitle + "</strong>》中发表评论。" + " </p>" + " <!-- 提示信息 -->" + " <div style=\"background-color: #fff8e1; border-left: 4px solid #ff9800; border-radius: 8px; padding: 25px; margin: 30px 0;\">" + " <p style=\"color: #3c4858; line-height: 1.8; margin: 0 0 15px 0; font-size: 15px; font-weight: 600;\">" + " ⚠️ 您的评论需要审核" + " </p>" + " <p style=\"color: #718096; line-height: 1.8; margin: 0; font-size: 14px;\">" + " 系统检测到您的评论可能包含不当内容,已自动提交审核。审核通过后,您的评论将正常显示。<br><br>" + " 我们致力于维护良好的社区环境,感谢您的理解与配合。" + " </p>" + " </div>" + " <!-- 评论内容 -->" + " <div style=\"background: #f8f9fa; border-left: 4px solid #cbd5e0; border-radius: 8px; padding: 20px; margin: 20px 0;\">" + " <p style=\"color: #718096; margin: 0 0 10px 0; font-size: 12px;\">您的评论内容</p>" + " <p style=\"color: #718096; font-size: 14px; line-height: 1.6; margin: 0; word-wrap: break-word;\">" + commentContent + "</p>" + " </div>" + " <!-- 检测到的敏感词 -->" + " <div style=\"background-color: #ffebee; border-left: 4px solid #f44336; border-radius: 8px; padding: 20px; margin: 20px 0;\">" + " <p style=\"color: #718096; margin: 0 0 10px 0; font-size: 12px;\">检测到的敏感词</p>" + " <div style=\"margin-top: 10px;\">" + sensitiveWordsHtml.toString() + "</div>" + " </div>" + " <!-- 查看按钮 -->" + " <div style=\"text-align: center; margin: 30px 0;\">" + " <a href=\"" + articleUrl + "\" style=\"display: inline-block; background: linear-gradient(135deg, #ff9800 0%, #fb8c00 100%); color: #ffffff; text-decoration: none; padding: 14px 40px; border-radius: 25px; font-size: 15px; font-weight: 600; box-shadow: 0 4px 15px rgba(255,152,0,0.3); transition: all 0.3s;\">查看页面</a>" + " </div>" + " </td>" + " </tr>" + " <!-- 底部 -->" + " <tr>" + " <td style=\"background: linear-gradient(135deg, #f8f9fa 0%, #eaecef 100%); padding: 30px; text-align: center; border-top: 1px solid #eaecef;\">" + " <p style=\"color: #718096; margin: 0 0 10px 0; font-size: 13px;\">" + " 此邮件由系统自动发送,请勿直接回复" + " </p>" + " <p style=\"color: #a7a9ad; margin: 0; font-size: 12px;\">" + " © " + LocalDate.now().getYear() + " 云梦泽的个人博客 · All rights reserved" + " </p>" + " </td>" + " </tr>" + " </table>" + " </td>" + " </tr>" + " </table>" + "</body>" + "</html>"; }
private String buildSensitiveWordAdminNotificationHtml(String commenterNickname, String commenterEmail, String commentContent, String articleTitle, String articleUrl, java.util.Map<String, String> sensitiveWordsWithSource) { StringBuilder sensitiveWordsHtml = new StringBuilder(); if (sensitiveWordsWithSource != null && !sensitiveWordsWithSource.isEmpty()) { for (Map.Entry<String, String> entry : sensitiveWordsWithSource.entrySet()) { sensitiveWordsHtml.append("<div style=\"margin: 8px 0; padding: 8px 12px; background-color: #fff; border-radius: 6px; border-left: 3px solid #f44336;\">") .append("<span style=\"color: #d32f2f; font-weight: 600; font-size: 14px;\">") .append(entry.getKey()) .append("</span>") .append("<span style=\"color: #9e9e9e; font-size: 12px; margin-left: 10px;\">来源: ") .append(entry.getValue()) .append("</span>") .append("</div>"); } } return "<!DOCTYPE html>" + "<html>" + "<head>" + " <meta charset=\"UTF-8\">" + " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" + "</head>" + "<body style=\"margin: 0; padding: 0; background: linear-gradient(135deg, #a5dff9 0%, #008c9e 100%); font-family: 'Segoe UI', Arial, sans-serif;\">" + " <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"padding: 40px 20px;\">" + " <tr>" + " <td align=\"center\">" + " <table width=\"600\" cellpadding=\"0\" cellspacing=\"0\" style=\"background-color: #f5fffa; border-radius: 12px; box-shadow: 0 12px 15px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19); overflow: hidden;\">" + " <!-- 头部 -->" + " <tr>" + " <td style=\"background: rgb(244, 67, 54); padding: 40px 30px; text-align: center;\">" + " <h1 style=\"color: #ffffff; margin: 0; font-size: 28px; font-weight: 600; letter-spacing: 1px;\">云梦泽的个人博客</h1>" + " <p style=\"color: #ffebee; margin: 10px 0 0 0; font-size: 14px;\">敏感词检测 - 待审核</p>" + " </td>" + " </tr>" + " <!-- 内容 -->" + " <tr>" + " <td style=\"padding: 50px 40px;\">" + " <h2 style=\"color: #3c4858; margin: 0 0 20px 0; font-size: 22px; font-weight: 600;\">🔍 检测到敏感词评论</h2>" + " <p style=\"color: #718096; line-height: 1.8; margin: 0 0 30px 0; font-size: 15px;\">" + " 系统检测到一条可能包含敏感词的评论,已自动设置为待审核状态,请及时处理。" + " </p>" + " <!-- 评论者信息 -->" + " <div style=\"background: linear-gradient(135deg, #f8f9fa 0%, #e8f4f8 100%); border-left: 4px solid #2196f3; border-radius: 8px; padding: 25px; margin: 30px 0; box-shadow: 0 2px 8px rgba(33,150,243,0.1);\">" + " <p style=\"color: #718096; margin: 0 0 10px 0; font-size: 13px; text-transform: uppercase; letter-spacing: 1px;\">评论者信息</p>" + " <p style=\"color: #3c4858; font-size: 15px; line-height: 1.8; margin: 0;\">" + " <strong>昵称:</strong>" + commenterNickname + "<br>" + " <strong>邮箱:</strong>" + commenterEmail + "<br>" + " <strong>文章:</strong>" + articleTitle + " </p>" + " </div>" + " <!-- 评论内容 -->" + " <div style=\"background-color: #ffebee; border-left: 4px solid #f44336; border-radius: 8px; padding: 25px; margin: 30px 0;\">" + " <p style=\"color: #718096; margin: 0 0 10px 0; font-size: 13px; text-transform: uppercase; letter-spacing: 1px;\">评论内容</p>" + " <p style=\"color: #3c4858; font-size: 15px; line-height: 1.8; margin: 0; word-wrap: break-word;\">" + commentContent + "</p>" + " </div>" + " <!-- 检测到的敏感词及来源 -->" + " <div style=\"background-color: #fff3e0; border-left: 4px solid #ff9800; border-radius: 8px; padding: 25px; margin: 30px 0;\">" + " <p style=\"color: #718096; margin: 0 0 15px 0; font-size: 13px; text-transform: uppercase; letter-spacing: 1px;\">🔍 检测到的敏感词及来源</p>" + " <div>" + sensitiveWordsHtml.toString() + "</div>" + " </div>" + " <!-- 查看按钮 -->" + " <div style=\"text-align: center; margin: 30px 0;\">" + " <a href=\"" + articleUrl + "\" style=\"display: inline-block; background: linear-gradient(135deg, #f44336 0%, #e53935 100%); color: #ffffff; text-decoration: none; padding: 14px 40px; border-radius: 25px; font-size: 15px; font-weight: 600; box-shadow: 0 4px 15px rgba(244,67,54,0.3); transition: all 0.3s; margin-right: 10px;\">查看页面</a>" + " </div>" + " </td>" + " </tr>" + " <!-- 底部 -->" + " <tr>" + " <td style=\"background: linear-gradient(135deg, #f8f9fa 0%, #eaecef 100%); padding: 30px; text-align: center; border-top: 1px solid #eaecef;\">" + " <p style=\"color: #718096; margin: 0 0 10px 0; font-size: 13px;\">" + " 此邮件由系统自动发送,请勿直接回复" + " </p>" + " <p style=\"color: #a7a9ad; margin: 0; font-size: 12px;\">" + " © " + LocalDate.now().getYear() + " 云梦泽的个人博客 · All rights reserved" + " </p>" + " </td>" + " </tr>" + " </table>" + " </td>" + " </tr>" + " </table>" + "</body>" + "</html>"; }
private String buildReplyNotificationHtml(String articleTitle, String replierNickname, String replyContent, String originalComment, String articleUrl) { return "<!DOCTYPE html>" + "<html>" + "<head>" + " <meta charset=\"UTF-8\">" + " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" + "</head>" + "<body style=\"margin: 0; padding: 0; background: linear-gradient(135deg, #a5dff9 0%, #008c9e 100%); font-family: 'Segoe UI', Arial, sans-serif;\">" + " <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"padding: 40px 20px;\">" + " <tr>" + " <td align=\"center\">" + " <table width=\"600\" cellpadding=\"0\" cellspacing=\"0\" style=\"background-color: #f5fffa; border-radius: 12px; box-shadow: 0 12px 15px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19); overflow: hidden;\">" + " <!-- 头部 -->" + " <tr>" + " <td style=\"background: rgb(125, 182, 191); padding: 40px 30px; text-align: center;\">" + " <h1 style=\"color: #2c3e50; margin: 0; font-size: 28px; font-weight: 600; letter-spacing: 1px;\">云梦泽的个人博客</h1>" + " <p style=\"color: #546e7a; margin: 10px 0 0 0; font-size: 14px;\">回复通知</p>" + " </td>" + " </tr>" + " <!-- 内容 -->" + " <tr>" + " <td style=\"padding: 50px 40px;\">" + " <h2 style=\"color: #3c4858; margin: 0 0 20px 0; font-size: 22px; font-weight: 600;\">您的评论收到了新回复</h2>" + " <p style=\"color: #718096; line-height: 1.8; margin: 0 0 30px 0; font-size: 15px;\">" + " <strong>" + replierNickname + "</strong> 在文章《<strong>" + articleTitle + "</strong>》中回复了您的评论。" + " </p>" + " <!-- 原评论 -->" + " <div style=\"background: #f8f9fa; border-left: 4px solid #cbd5e0; border-radius: 8px; padding: 20px; margin: 20px 0;\">" + " <p style=\"color: #718096; margin: 0 0 10px 0; font-size: 12px;\">您的评论</p>" + " <p style=\"color: #718096; font-size: 14px; line-height: 1.6; margin: 0; word-wrap: break-word;\">" + originalComment + "</p>" + " </div>" + " <!-- 回复内容 -->" + " <div style=\"background: linear-gradient(135deg, #f8f9fa 0%, #e8f4f8 100%); border-left: 4px solid #52c41a; border-radius: 8px; padding: 25px; margin: 20px 0; box-shadow: 0 2px 8px rgba(82,196,26,0.1);\">" + " <p style=\"color: #718096; margin: 0 0 10px 0; font-size: 13px; text-transform: uppercase; letter-spacing: 1px;\">回复内容</p>" + " <p style=\"color: #3c4858; font-size: 15px; line-height: 1.8; margin: 0; word-wrap: break-word;\">" + replyContent + "</p>" + " </div>" + " <!-- 查看按钮 -->" + " <div style=\"text-align: center; margin: 30px 0;\">" + " <a href=\"" + articleUrl + "\" style=\"display: inline-block; background: linear-gradient(135deg, #52c41a 0%, #73d13d 100%); color: #ffffff; text-decoration: none; padding: 14px 40px; border-radius: 25px; font-size: 15px; font-weight: 600; box-shadow: 0 4px 15px rgba(82,196,26,0.3); transition: all 0.3s;\">查看回复</a>" + " </div>" + " </td>" + " </tr>" + " <!-- 底部 -->" + " <tr>" + " <td style=\"background: linear-gradient(135deg, #f8f9fa 0%, #eaecef 100%); padding: 30px; text-align: center; border-top: 1px solid #eaecef;\">" + " <p style=\"color: #718096; margin: 0 0 10px 0; font-size: 13px;\">" + " 此邮件由系统自动发送,请勿直接回复" + " </p>" + " <p style=\"color: #a7a9ad; margin: 0; font-size: 12px;\">" + " © " + LocalDate.now().getYear() + " 云梦泽的个人博客 · All rights reserved" + " </p>" + " </td>" + " </tr>" + " </table>" + " </td>" + " </tr>" + " </table>" + "</body>" + "</html>"; }
private String buildCommentApprovedNotificationHtml(String nickname, String commentContent, String articleTitle, String articleUrl) { return "<!DOCTYPE html>" + "<html>" + "<head>" + " <meta charset=\"UTF-8\">" + " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" + "</head>" + "<body style=\"margin: 0; padding: 0; background: linear-gradient(135deg, #a5dff9 0%, #008c9e 100%); font-family: 'Segoe UI', Arial, sans-serif;\">" + " <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"padding: 40px 20px;\">" + " <tr>" + " <td align=\"center\">" + " <table width=\"600\" cellpadding=\"0\" cellspacing=\"0\" style=\"background-color: #f5fffa; border-radius: 12px; box-shadow: 0 12px 15px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19); overflow: hidden;\">" + " <!-- 头部 -->" + " <tr>" + " <td style=\"background: rgb(82, 196, 26); padding: 40px 30px; text-align: center;\">" + " <h1 style=\"color: #ffffff; margin: 0; font-size: 28px; font-weight: 600; letter-spacing: 1px;\">云梦泽的个人博客</h1>" + " <p style=\"color: #f6ffed; margin: 10px 0 0 0; font-size: 14px;\">评论审核通知</p>" + " </td>" + " </tr>" + " <!-- 内容 -->" + " <tr>" + " <td style=\"padding: 50px 40px;\">" + " <h2 style=\"color: #3c4858; margin: 0 0 20px 0; font-size: 22px; font-weight: 600;\"> 恭喜," + nickname + "!</h2>" + " <p style=\"color: #718096; line-height: 1.8; margin: 0 0 30px 0; font-size: 15px;\">" + " 您在《<strong>" + articleTitle + "</strong>》中发表的评论已通过审核,现已正常显示。" + " </p>" + " <!-- 成功提示 -->" + " <div style=\"background-color: #f6ffed; border-left: 4px solid #52c41a; border-radius: 8px; padding: 25px; margin: 30px 0;\">" + " <p style=\"color: #3c4858; line-height: 1.8; margin: 0 0 15px 0; font-size: 15px; font-weight: 600;\">" + " - ̗̀ ෆ( ˶’ᵕ’˶)ෆ ̖́- 审核通过" + " </p>" + " <p style=\"color: #718096; line-height: 1.8; margin: 0; font-size: 14px;\">" + " 您的评论已通过审核,其他用户现在可以看到您的评论了。<br><br>" + " <span style=\"display: block; text-align: center; font-size: 20px; margin: 10px 0;\">ʕ ◦`꒳´◦ʔ</span><br>" + " 感谢您的留言!" + " </p>" + " </div>" + " <!-- 评论内容 -->" + " <div style=\"background: linear-gradient(135deg, #f8f9fa 0%, #e8f4f8 100%); border-left: 4px solid #52c41a; border-radius: 8px; padding: 25px; margin: 30px 0; box-shadow: 0 2px 8px rgba(82,196,26,0.1);\">" + " <p style=\"color: #718096; margin: 0 0 10px 0; font-size: 13px; text-transform: uppercase; letter-spacing: 1px;\">您的评论内容</p>" + " <p style=\"color: #3c4858; font-size: 15px; line-height: 1.8; margin: 0; word-wrap: break-word;\">" + commentContent + "</p>" + " </div>" + " <!-- 查看按钮 -->" + " <div style=\"text-align: center; margin: 30px 0;\">" + " <a href=\"" + articleUrl + "\" style=\"display: inline-block; background: linear-gradient(135deg, #52c41a 0%, #73d13d 100%); color: #ffffff; text-decoration: none; padding: 14px 40px; border-radius: 25px; font-size: 15px; font-weight: 600; box-shadow: 0 4px 15px rgba(82,196,26,0.3); transition: all 0.3s;\">查看评论</a>" + " </div>" + " </td>" + " </tr>" + " <!-- 底部 -->" + " <tr>" + " <td style=\"background: linear-gradient(135deg, #f8f9fa 0%, #eaecef 100%); padding: 30px; text-align: center; border-top: 1px solid #eaecef;\">" + " <p style=\"color: #718096; margin: 0 0 10px 0; font-size: 13px;\">" + " 此邮件由系统自动发送,请勿直接回复" + " </p>" + " <p style=\"color: #a7a9ad; margin: 0; font-size: 12px;\">" + " © " + LocalDate.now().getYear() + " 云梦泽的个人博客 · All rights reserved" + " </p>" + " </td>" + " </tr>" + " </table>" + " </td>" + " </tr>" + " </table>" + "</body>" + "</html>"; }
private String buildCommentRejectedNotificationHtml(String nickname, String commentContent, String articleTitle, String articleUrl) { return "<!DOCTYPE html>" + "<html>" + "<head>" + " <meta charset=\"UTF-8\">" + " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" + "</head>" + "<body style=\"margin: 0; padding: 0; background: linear-gradient(135deg, #a5dff9 0%, #008c9e 100%); font-family: 'Segoe UI', Arial, sans-serif;\">" + " <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"padding: 40px 20px;\">" + " <tr>" + " <td align=\"center\">" + " <table width=\"600\" cellpadding=\"0\" cellspacing=\"0\" style=\"background-color: #f5fffa; border-radius: 12px; box-shadow: 0 12px 15px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19); overflow: hidden;\">" + " <!-- 头部 -->" + " <tr>" + " <td style=\"background: rgb(244, 67, 54); padding: 40px 30px; text-align: center;\">" + " <h1 style=\"color: #ffffff; margin: 0; font-size: 28px; font-weight: 600; letter-spacing: 1px;\">云梦泽的个人博客</h1>" + " <p style=\"color: #ffebee; margin: 10px 0 0 0; font-size: 14px;\">评论审核通知</p>" + " </td>" + " </tr>" + " <!-- 内容 -->" + " <tr>" + " <td style=\"padding: 50px 40px;\">" + " <h2 style=\"color: #3c4858; margin: 0 0 20px 0; font-size: 22px; font-weight: 600;\">您好," + nickname + "!</h2>" + " <p style=\"color: #718096; line-height: 1.8; margin: 0 0 30px 0; font-size: 15px;\">" + " 很抱歉,您在《<strong>" + articleTitle + "</strong>》中发表的评论未能通过审核。" + " </p>" + " <!-- 提示信息 -->" + " <div style=\"background-color: #ffebee; border-left: 4px solid #f44336; border-radius: 8px; padding: 25px; margin: 30px 0;\">" + " <p style=\"color: #3c4858; line-height: 1.8; margin: 0 0 15px 0; font-size: 15px; font-weight: 600;\">" + " ˚ʚ。・-・。ɞ˚ 审核未通过" + " </p>" + " <p style=\"color: #718096; line-height: 1.8; margin: 0; font-size: 14px;\">" + " 经过审核,您发布的内容性质太过于敏感,以至于容易送博主进去喝茶,因此未能通过审核。<br><br>" + " <span style=\"display: block; text-align: center; font-size: 20px; margin: 10px 0;\">( ⩌⤚⩌)</span><br>" + " 我们致力于维护良好的社区环境,希望您能理解。如有疑问,欢迎联系我们。" + " </p>" + " </div>" + " <!-- 评论内容 -->" + " <div style=\"background: #f8f9fa; border-left: 4px solid #cbd5e0; border-radius: 8px; padding: 20px; margin: 20px 0;\">" + " <p style=\"color: #718096; margin: 0 0 10px 0; font-size: 12px;\">您的评论内容</p>" + " <p style=\"color: #718096; font-size: 14px; line-height: 1.6; margin: 0; word-wrap: break-word;\">" + commentContent + "</p>" + " </div>" + " <!-- 查看按钮 -->" + " <div style=\"text-align: center; margin: 30px 0;\">" + " <a href=\"" + articleUrl + "\" style=\"display: inline-block; background: linear-gradient(135deg, #f44336 0%, #e53935 100%); color: #ffffff; text-decoration: none; padding: 14px 40px; border-radius: 25px; font-size: 15px; font-weight: 600; box-shadow: 0 4px 15px rgba(244,67,54,0.3); transition: all 0.3s;\">查看页面</a>" + " </div>" + " </td>" + " </tr>" + " <!-- 底部 -->" + " <tr>" + " <td style=\"background: linear-gradient(135deg, #f8f9fa 0%, #eaecef 100%); padding: 30px; text-align: center; border-top: 1px solid #eaecef;\">" + " <p style=\"color: #718096; margin: 0 0 10px 0; font-size: 13px;\">" + " 此邮件由系统自动发送,请勿直接回复" + " </p>" + " <p style=\"color: #a7a9ad; margin: 0; font-size: 12px;\">" + " © " + LocalDate.now().getYear() + " 云梦泽的个人博客 · All rights reserved" + " </p>" + " </td>" + " </tr>" + " </table>" + " </td>" + " </tr>" + " </table>" + "</body>" + "</html>"; }
private String getThemeColor(String scene) { switch (scene) { case "登录": return "#30a9de"; case "注册": return "#52c41a"; case "重置密码": return "#ff6b6b"; default: return "#30a9de"; } }
private String getGreeting(String scene) { switch (scene) { case "注册": return "⌯ᵔᗜᵔ⌯ಣ 欢迎加入!"; case "重置密码": return "密码重置"; default: return " (๓´˘`๓) 您好!"; } } }
|