From 918ada9a82c7c35e90c670a2d071b9ae454face4 Mon Sep 17 00:00:00 2001 From: Ziin Date: Wed, 13 Aug 2025 21:58:51 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E9=82=AE=E4=BB=B6=E5=8F=91?= =?UTF-8?q?=E9=80=81=E4=B8=BA=E5=BC=82=E6=AD=A5=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mail/service/MailServiceImpl.java | 959 +++++++++--------- 1 file changed, 494 insertions(+), 465 deletions(-) diff --git a/src/main/java/vvpkassistant/mail/service/MailServiceImpl.java b/src/main/java/vvpkassistant/mail/service/MailServiceImpl.java index 45a3133..5f21840 100644 --- a/src/main/java/vvpkassistant/mail/service/MailServiceImpl.java +++ b/src/main/java/vvpkassistant/mail/service/MailServiceImpl.java @@ -1,6 +1,7 @@ package vvpkassistant.mail.service; import cn.dev33.satoken.temp.SaTempUtil; +import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.util.RandomUtil; import cn.hutool.extra.mail.MailUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -56,160 +57,167 @@ public class MailServiceImpl implements MailService { if (emailSendCache.getIfPresent(emailAddress) != null) { throw new BusinessException(ErrorCode.EMAIL_SEND_FREQUENT); } - MailUtil.send(emailAddress, "激活你的账号", "\n" + - "\n" + - "\n" + - " \n" + - " \n" + - " Account Activation\n" + - " \n" + - "\n" + - "\n" + - "
\n" + - "
\n" + - " \n" + - "

Account Activation

\n" + - "

Please click the button below to activate your account

\n" + - " \n" + - " \n" + - " Activate Account\n" + - " \n" + - " \n" + - "
\n" + - "
Important Notice:
\n" + - "
\n" + - " • This activation link is valid for 24 hours
\n" + - " • Please do not share this link with anyone
\n" + - " • If you didn't register an account, please ignore this message\n" + - "
\n" + - "
\n" + - " \n" + - "
\n" + - " This is an automated message. Please do not reply to this email.\n" + - "
\n" + - "
\n" + - "\n" + - "\n", true); + ThreadUtil.execute(() -> { + try { + MailUtil.send(emailAddress, "激活你的账号", "\n" + + "\n" + + "\n" + + " \n" + + " \n" + + " Account Activation\n" + + " \n" + + "\n" + + "\n" + + "
\n" + + "
\n" + + " \n" + + "

Account Activation

\n" + + "

Please click the button below to activate your account

\n" + + " \n" + + " \n" + + " Activate Account\n" + + " \n" + + " \n" + + "
\n" + + "
Important Notice:
\n" + + "
\n" + + " • This activation link is valid for 24 hours
\n" + + " • Please do not share this link with anyone
\n" + + " • If you didn't register an account, please ignore this message\n" + + "
\n" + + "
\n" + + " \n" + + "
\n" + + " This is an automated message. Please do not reply to this email.\n" + + "
\n" + + "
\n" + + "\n" + + "\n", true); + log.info("账号激活邮件发送成功,邮箱地址:{},用户 Id:{}", emailAddress,userId); + } catch (Exception e) { + log.error("账号激活邮件发送失败,邮箱地址:{},用户 Id:{}",emailAddress,userId); + } + }); emailSendCache.put(emailAddress, userId); } @@ -220,160 +228,168 @@ public class MailServiceImpl implements MailService { if (emailSendCache.getIfPresent(emailAddress) != null) { throw new BusinessException(ErrorCode.EMAIL_SEND_FREQUENT); } - MailUtil.send(emailAddress, "验证你的邮箱", "\n" + - "\n" + - "\n" + - " \n" + - " \n" + - " Account Activation\n" + - " \n" + - "\n" + - "\n" + - "
\n" + - "
\n" + - " \n" + - "

Verification Mail

\n" + - "

Please click the button below to verification your mail

\n" + - " \n" + - " \n" + - " Verification\n" + - " \n" + - " \n" + - "
\n" + - "
Important Notice:
\n" + - "
\n" + - " • This activation link is valid for 10 minutes
\n" + - " • Please do not share this link with anyone
\n" + - " • If you didn't register an account, please ignore this message\n" + - "
\n" + - "
\n" + - " \n" + - "
\n" + - " This is an automated message. Please do not reply to this email.\n" + - "
\n" + - "
\n" + - "\n" + - "\n", true); + ThreadUtil.execAsync(() ->{ + try { + MailUtil.send(emailAddress, "验证你的邮箱", "\n" + + "\n" + + "\n" + + " \n" + + " \n" + + " Account Activation\n" + + " \n" + + "\n" + + "\n" + + "
\n" + + "
\n" + + " \n" + + "

Verification Mail

\n" + + "

Please click the button below to verification your mail

\n" + + " \n" + + " \n" + + " Verification\n" + + " \n" + + " \n" + + "
\n" + + "
Important Notice:
\n" + + "
\n" + + " • This activation link is valid for 10 minutes
\n" + + " • Please do not share this link with anyone
\n" + + " • If you didn't register an account, please ignore this message\n" + + "
\n" + + "
\n" + + " \n" + + "
\n" + + " This is an automated message. Please do not reply to this email.\n" + + "
\n" + + "
\n" + + "\n" + + "\n", true); + log.info("邮箱验证发送失败,邮箱地址:{},用户 Id: {}",emailAddress,userId ); + }catch (Exception e) { + log.error("邮箱验证发送失败,邮箱地址:{},用户 Id: {}",emailAddress,userId ); + } + }); + emailSendCache.put(emailAddress, userId); } @@ -410,160 +426,167 @@ public class MailServiceImpl implements MailService { public void sendForgetPassWordMail(String mailAddress, Integer userId) { if (checkCache(mailAddress)){ String token = SaTempUtil.createToken(userId, 600); - MailUtil.send(mailAddress, "验证你的邮箱", "\n" + - "\n" + - "\n" + - " \n" + - " \n" + - " Account Activation\n" + - " \n" + - "\n" + - "\n" + - "
\n" + - "
\n" + - " \n" + - "

Verification Mail

\n" + - "

Please click the button below to reset your password

\n" + - " \n" + - " \n" + - " Reset PassWord\n" + - " \n" + - " \n" + - "
\n" + - "
Important Notice:
\n" + - "
\n" + - " • This activation link is valid for 10 minutes
\n" + - " • Please do not share this link with anyone
\n" + - " • If you didn't register an account, please ignore this message\n" + - "
\n" + - "
\n" + - " \n" + - "
\n" + - " This is an automated message. Please do not reply to this email.\n" + - "
\n" + - "
\n" + - "\n" + - "\n", true); + ThreadUtil.execAsync(() ->{ + try { + MailUtil.send(mailAddress, "验证你的邮箱", "\n" + + "\n" + + "\n" + + " \n" + + " \n" + + " Account Activation\n" + + " \n" + + "\n" + + "\n" + + "
\n" + + "
\n" + + " \n" + + "

Verification Mail

\n" + + "

Please click the button below to reset your password

\n" + + " \n" + + " \n" + + " Reset PassWord\n" + + " \n" + + " \n" + + "
\n" + + "
Important Notice:
\n" + + "
\n" + + " • This activation link is valid for 10 minutes
\n" + + " • Please do not share this link with anyone
\n" + + " • If you didn't register an account, please ignore this message\n" + + "
\n" + + "
\n" + + " \n" + + "
\n" + + " This is an automated message. Please do not reply to this email.\n" + + "
\n" + + "
\n" + + "\n" + + "\n", true); + log.info("找回密码邮件发送成功,邮箱地址:{},用户 Id:{}", mailAddress,userId); + }catch (Exception e) { + log.error("找回密码邮件发送失败,邮箱地址:{},用户 Id:{}", mailAddress,userId); + } + }); emailSendCache.put(mailAddress, userId); } @@ -583,9 +606,15 @@ public class MailServiceImpl implements MailService { String code = RandomUtil.randomString(6); emailSendCache.put(mailModel.getMailAddress(), code); CacheHolder.VERIFICATION_MAIL.put(code, mailModel.getMailAddress()); - MailUtil.send(mailModel.getMailAddress(),"your Verification code is :" + code, - "your Verification code is :" + code,false); - log.info("sendMailto:{},Verification code is :{}", mailModel.getMailAddress(),code); + ThreadUtil.execAsync(() -> { + try { + MailUtil.send(mailModel.getMailAddress(),"your Verification code is :" + code, + "your Verification code is :" + code,false); + log.info("sendMailto:{},Verification code is :{}", mailModel.getMailAddress(),code); + }catch (Exception e){ + log.error("发送邮件失败, address={}, code={}", mailModel.getMailAddress(), code, e); + } + }); } return true; }