2
0

fix: 邮件标题自定义

This commit is contained in:
caiyuchao
2025-04-16 16:16:15 +08:00
parent b472c6a2a7
commit 559a659797
5 changed files with 17 additions and 138 deletions

View File

@@ -2,6 +2,7 @@ package org.wfc.user.controller;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
@@ -56,7 +57,11 @@ public class UEmailController extends BaseController {
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);
String subject = mailProperties.getSubject();
if (StrUtil.isBlank(subject)) {
subject = "Your WANFI Verification Code";
}
MailUtils.sendHtml(email, subject, htmlStr);
} catch (Exception e) {
log.error("email verification code send failed => {}", e.getMessage());
return R.fail(e.getMessage());

View File

@@ -1,68 +0,0 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>验证码邮件</title>
<style>
/* 内联样式兼容邮件客户端 */
@media only screen and (max-width: 600px) {
.container {
width: 100% !important;
}
.code {
font-size: 24px !important;
}
}
</style>
</head>
<body style="margin: 0; padding: 0; font-family: Arial, sans-serif; background-color: #f5f5f5;">
<table role="presentation" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" style="padding: 20px 0;">
<!-- 容器开始 -->
<table class="container" width="600" border="0" cellspacing="0" cellpadding="0" style="background-color: #ffffff; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);">
<!-- 头部 -->
<tr>
<td style="padding: 30px 20px; border-bottom: 1px solid #eeeeee;">
<img src="[您的LogoURL]" alt="公司Logo" width="120" style="display: block; margin: 0 auto;">
</td>
</tr>
<!-- 内容区 -->
<tr>
<td style="padding: 40px 30px;">
<h2 style="color: #333333; margin: 0 0 20px 0;">您的验证码</h2>
<p style="color: #666666; line-height: 1.6; margin: 0 0 20px 0;">
请使用以下验证码完成操作:
</p>
<div style="background-color: #f8f9fa; padding: 15px; border-radius: 4px; text-align: center; margin: 20px 0;">
<strong class="code" style="font-size: 28px; color: #2d3748; letter-spacing: 3px;"> <span th:text="${verificationCode}"></span> </strong>
</div>
<p style="color: #999999; font-size: 12px; margin: 20px 0;">
该验证码将在<span th:text="${expirationTime}"></span> 分钟后失效,请及时使用
</p>
</td>
</tr>
<!-- 底部 -->
<tr>
<td style="padding: 20px 30px; background-color: #f8f9fa; border-radius: 0 0 8px 8px;">
<p style="color: #999999; font-size: 12px; margin: 0;">
此为系统自动发送邮件,请勿直接回复<br>
如有疑问请联系 <a href="mailto:support@example.com" style="color: #4299e1;">support@example.com</a><br>
© 2023 您的公司名称。保留所有权利
</p>
<p style="color: #999999; font-size: 12px; margin: 10px 0 0 0;">
<a href="{{unsubscribe_link}}" style="color: #718096; text-decoration: none;">退订邮件</a>
</p>
</td>
</tr>
</table>
<!-- 容器结束 -->
</td>
</tr>
</table>
</body>
</html>