diff --git a/wfc-modules/wfc-system/pom.xml b/wfc-modules/wfc-system/pom.xml index b6dd658..6f4602d 100644 --- a/wfc-modules/wfc-system/pom.xml +++ b/wfc-modules/wfc-system/pom.xml @@ -90,6 +90,11 @@ mapstruct + + org.springframework.boot + spring-boot-starter-thymeleaf + + diff --git a/wfc-modules/wfc-system/src/main/java/org/wfc/system/controller/SysEmailController.java b/wfc-modules/wfc-system/src/main/java/org/wfc/system/controller/SysEmailController.java index 62fdad1..d840012 100644 --- a/wfc-modules/wfc-system/src/main/java/org/wfc/system/controller/SysEmailController.java +++ b/wfc-modules/wfc-system/src/main/java/org/wfc/system/controller/SysEmailController.java @@ -8,6 +8,8 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.context.Context; import org.wfc.common.core.constant.Constants; import org.wfc.common.core.constant.GlobalConstants; import org.wfc.common.core.domain.R; @@ -34,6 +36,7 @@ public class SysEmailController extends BaseController { private final MailProperties mailProperties; private final RedisService redisService; + private final TemplateEngine templateEngine; /** * 邮箱验证码 @@ -49,7 +52,11 @@ public class SysEmailController extends BaseController { String code = RandomUtil.randomNumbers(4); redisService.setCacheObject(key, code, Constants.MAIL_CAPTCHA_EXPIRATION, TimeUnit.MINUTES); try { - MailUtils.sendText(email, "Your WANFI verification code", "Hi\nYour verification code is:\n" + code + "\nThis code will expire in " + Constants.MAIL_CAPTCHA_EXPIRATION + " minutes.\nFor your security, don't share it with anyone."); + Context context = new Context(); + context.setVariable("verificationCode", code); + context.setVariable("expirationTime", Constants.MAIL_CAPTCHA_EXPIRATION); + String htmlStr = templateEngine.process("mail", context); + MailUtils.sendHtml(email, "Your WANFI verification code", htmlStr); } catch (Exception e) { log.error("email verification code send failed => {}", e.getMessage()); return R.fail(e.getMessage()); diff --git a/wfc-modules/wfc-system/src/main/resources/templates/mail.html b/wfc-modules/wfc-system/src/main/resources/templates/mail.html new file mode 100644 index 0000000..7d6e42f --- /dev/null +++ b/wfc-modules/wfc-system/src/main/resources/templates/mail.html @@ -0,0 +1,68 @@ + + + + + + 验证码邮件 + + + + + + + + + + + + + + + + + + + 您的验证码 + + 请使用以下验证码完成操作: + + + + + + + 该验证码将在 分钟后失效,请及时使用 + + + + + + + + + 此为系统自动发送邮件,请勿直接回复 + 如有疑问请联系 support@example.com + © 2023 您的公司名称。保留所有权利 + + + 退订邮件 + + + + + + + + + + \ No newline at end of file diff --git a/wfc-modules/wfc-user/pom.xml b/wfc-modules/wfc-user/pom.xml index bc5e3b4..b2f3265 100644 --- a/wfc-modules/wfc-user/pom.xml +++ b/wfc-modules/wfc-user/pom.xml @@ -103,6 +103,11 @@ org.wfc wfc-common-mail + + + org.springframework.boot + spring-boot-starter-thymeleaf + diff --git a/wfc-modules/wfc-user/src/main/java/org/wfc/user/controller/UEmailController.java b/wfc-modules/wfc-user/src/main/java/org/wfc/user/controller/UEmailController.java index 15895ff..94903c2 100644 --- a/wfc-modules/wfc-user/src/main/java/org/wfc/user/controller/UEmailController.java +++ b/wfc-modules/wfc-user/src/main/java/org/wfc/user/controller/UEmailController.java @@ -8,6 +8,8 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.context.Context; import org.wfc.common.core.constant.Constants; import org.wfc.common.core.constant.GlobalConstants; import org.wfc.common.core.domain.R; @@ -34,6 +36,7 @@ public class UEmailController extends BaseController { private final MailProperties mailProperties; private final RedisService redisService; + private final TemplateEngine templateEngine; /** * 邮箱验证码 @@ -49,7 +52,11 @@ public class UEmailController extends BaseController { String code = RandomUtil.randomNumbers(4); redisService.setCacheObject(key, code, Constants.MAIL_CAPTCHA_EXPIRATION, TimeUnit.MINUTES); try { - MailUtils.sendText(email, "Your WANFI verification code", "Hi\nYour verification code is:\n" + code + "\nThis code will expire in " + Constants.MAIL_CAPTCHA_EXPIRATION + " minutes.\nFor your security, don't share it with anyone."); + Context context = new Context(); + context.setVariable("verificationCode", code); + context.setVariable("expirationTime", Constants.MAIL_CAPTCHA_EXPIRATION); + String htmlStr = templateEngine.process("mail", context); + MailUtils.sendHtml(email, "Your WANFI verification code", htmlStr); } catch (Exception e) { log.error("email verification code send failed => {}", e.getMessage()); return R.fail(e.getMessage()); diff --git a/wfc-modules/wfc-user/src/main/resources/templates/mail.html b/wfc-modules/wfc-user/src/main/resources/templates/mail.html new file mode 100644 index 0000000..7d6e42f --- /dev/null +++ b/wfc-modules/wfc-user/src/main/resources/templates/mail.html @@ -0,0 +1,68 @@ + + + + + + 验证码邮件 + + + + + + + + + + + + + + + + + + + 您的验证码 + + 请使用以下验证码完成操作: + + + + + + + 该验证码将在 分钟后失效,请及时使用 + + + + + + + + + 此为系统自动发送邮件,请勿直接回复 + 如有疑问请联系 support@example.com + © 2023 您的公司名称。保留所有权利 + + + 退订邮件 + + + + + + + + + + \ No newline at end of file
+ 请使用以下验证码完成操作: +
+ 该验证码将在 分钟后失效,请及时使用 +
+ 此为系统自动发送邮件,请勿直接回复 + 如有疑问请联系 support@example.com + © 2023 您的公司名称。保留所有权利 +
+ 退订邮件 +