From e4326036f86657685bc357eefa1de3525c4a4def Mon Sep 17 00:00:00 2001
From: wangjingyi <wangjingyifighting@live.com>
Date: Sat, 26 Mar 2022 08:06:32 +0800
Subject: [PATCH] =?UTF-8?q?fix=20=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81=20?=
 =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E4=BF=A1=E6=81=AF=E8=A3=85=E8=BD=BD=20?=
 =?UTF-8?q?=E5=9C=A8convert=E4=B8=AD=E5=A4=84=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../system/convert/mail/MailAccountConvert.java      | 12 ++++++++++++
 .../service/mail/impl/MailAccountServiceImpl.java    | 10 ++--------
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java
index a288dd84a..fe768efbd 100644
--- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java
+++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java
@@ -1,5 +1,6 @@
 package cn.iocoder.yudao.module.system.convert.mail;
 
+import cn.hutool.extra.mail.MailAccount;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountBaseVO;
 import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
@@ -19,4 +20,15 @@ public interface MailAccountConvert {
     PageResult<MailAccountBaseVO>  convertPage(PageResult<MailAccountDO> pageResult);
 
     List<MailAccountBaseVO> convertList02(List<MailAccountDO> list);
+
+    default MailAccount convertAccount(MailAccountDO mailAccountDO){
+        return new MailAccount()
+                .setHost(mailAccountDO.getHost())
+                .setPort(mailAccountDO.getPort())
+                .setAuth(true)
+                .setFrom(mailAccountDO.getFrom())
+                .setUser(mailAccountDO.getUsername())
+                .setPass(mailAccountDO.getPassword())
+                .setSslEnable(mailAccountDO.getSslEnable());
+    };
 }
diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java
index 98aa646c7..0c0d86eba 100644
--- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java
+++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java
@@ -106,14 +106,8 @@ public class MailAccountServiceImpl implements MailAccountService {
         //List<String> fileIds = mailSendVO.getFileIds();
 
         //装载账号信息
-        MailAccount account = new MailAccount();
-        account.setHost(mailAccountDO.getHost());
-        account.setPort(mailAccountDO.getPort());
-        account.setAuth(true);
-        account.setFrom(mailAccountDO.getFrom());
-        account.setUser(mailAccountDO.getUsername());
-        account.setPass(mailAccountDO.getPassword());
-        account.setSslEnable(mailAccountDO.getSslEnable());
+        MailAccount account  = MailAccountConvert.INSTANCE.convertAccount(mailAccountDO);
+
         //发送
         MailUtil.send(account , mailSendVO.getTos() , mailSendVO.getTitle() , mailSendVO.getContent() , false);
     }