24282 2 years ago
parent
commit
4b70e19b99

+ 19 - 3
src/main/java/com/fjhx/email/controller/MailController.java

@@ -7,9 +7,11 @@ import com.fjhx.email.config.exception.ServiceException;
 import com.fjhx.email.entity.dto.GetMessagePageDto;
 import com.fjhx.email.entity.dto.MailSyncInfo;
 import com.fjhx.email.entity.dto.MailboxInfo;
+import com.fjhx.email.entity.dto.SendDto;
 import com.fjhx.email.entity.vo.MessageDetailVo;
 import com.fjhx.email.entity.vo.MessageVo;
 import com.fjhx.email.service.IMailService;
+import com.fjhx.email.utils.EmailUtil;
 import com.fjhx.email.utils.HxHttpUtil;
 import com.fjhx.email.utils.PageWrapper;
 import lombok.extern.slf4j.Slf4j;
@@ -41,15 +43,15 @@ public class MailController {
             }
         } catch (IORuntimeException e) {
             log.error("获取主服务在线用户超时");
-            ThreadUtil.sleep(1000 * 5);
+            ThreadUtil.sleep(1000 * 10);
             checkStart();
         } catch (ServiceException e) {
             log.error("主服务返回信息错误:{}", e.getMessage());
-            ThreadUtil.sleep(1000 * 5);
+            ThreadUtil.sleep(1000 * 10);
             checkStart();
         } catch (Exception e) {
             log.error("解析错误", e);
-            ThreadUtil.sleep(1000 * 5);
+            ThreadUtil.sleep(1000 * 10);
             checkStart();
         }
     }
@@ -112,5 +114,19 @@ public class MailController {
         return R.ok(vo);
     }
 
+    /**
+     * 发送邮件
+     */
+    @PostMapping("/sendMail/{host}/{user}/{password}")
+    public R sendMail(@PathVariable("host") String host, @PathVariable("user") String user,
+                      @PathVariable("password") String password, @RequestBody SendDto sendDto) {
+        try {
+            EmailUtil.sendMail(host, user, password, sendDto);
+        } catch (Exception e) {
+            log.error("发送邮件失败:", e);
+            throw new ServiceException("发送邮件失败");
+        }
+        return R.ok();
+    }
 
 }

+ 6 - 1
src/main/java/com/fjhx/email/entity/dto/SendDto.java

@@ -10,9 +10,14 @@ import java.util.List;
 public class SendDto {
 
     /**
+     * 1个人邮箱 2企业邮箱
+     */
+    private Integer type;
+
+    /**
      * 邮箱id
      */
-    String mailboxId;
+    private Long mailboxId;
 
     /**
      * 发送

+ 0 - 1
src/main/java/com/fjhx/email/mapper/xml/MailMapper.xml

@@ -86,5 +86,4 @@
         )
     </select>
 
-
 </mapper>