24282 2 years ago
parent
commit
188c0828cd

+ 13 - 0
src/main/java/com/fjhx/controller/AccountController.java

@@ -1,5 +1,6 @@
 package com.fjhx.controller;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.fjhx.base.R;
 import com.fjhx.config.redis.RedisCache;
@@ -9,6 +10,7 @@ import com.fjhx.service.IAccountService;
 import com.fjhx.vo.BindingVo;
 import com.fjhx.vo.ListenerVo;
 import com.fjhx.vo.ProgressVo;
+import com.fjhx.vo.SubmitVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -52,4 +54,15 @@ public class AccountController {
         return R.ok();
     }
 
+    /**
+     * 发送邮件
+     */
+    @PostMapping("submit")
+    public R submit(@RequestBody SubmitVo submitVo) {
+        System.out.println(JSON.toJSONString(submitVo));
+        accountService.submit(submitVo);
+        return R.ok();
+    }
+
+
 }

+ 6 - 0
src/main/java/com/fjhx/service/IAccountService.java

@@ -3,6 +3,7 @@ package com.fjhx.service;
 import com.fjhx.entity.EmailInfo;
 import com.fjhx.vo.BindingVo;
 import com.fjhx.vo.ListenerVo;
+import com.fjhx.vo.SubmitVo;
 
 public interface IAccountService {
 
@@ -16,4 +17,9 @@ public interface IAccountService {
      */
     void listener(ListenerVo listenerVo);
 
+    /**
+     * 发送邮件
+     */
+    void submit(SubmitVo submitVo);
+
 }

+ 5 - 0
src/main/java/com/fjhx/service/impl/AccountServiceImpl.java

@@ -115,6 +115,11 @@ public class AccountServiceImpl implements IAccountService {
 
     }
 
+    @Override
+    public void submit(SubmitVo submitVo) {
+        EmailEngineUtil.submit(submitVo);
+    }
+
     /**
      * 添加邮件信息
      */

+ 8 - 0
src/main/java/com/fjhx/utils/EmailEngineUtil.java

@@ -3,6 +3,8 @@ package com.fjhx.utils;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.lang.Assert;
 import cn.hutool.http.HttpUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.fjhx.vo.*;
 import lombok.extern.slf4j.Slf4j;
 import org.jetbrains.annotations.NotNull;
@@ -113,6 +115,12 @@ public class EmailEngineUtil {
         return true;
     }
 
+    public static void submit(SubmitVo submitVo) {
+        String address = submitVo.getFrom().getAddress();
+        JSONObject submitJson = JSON.parseObject(JSON.toJSONString(submitVo));
+        String result = post("v1/account/" + address + "/submit", submitJson, String.class);
+    }
+
     /**
      * 生成验证邮箱配置实体
      */

+ 101 - 0
src/main/java/com/fjhx/vo/SubmitVo.java

@@ -0,0 +1,101 @@
+package com.fjhx.vo;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class SubmitVo {
+
+    // private ReferenceDTO reference;
+
+    // private EnvelopeDTO envelope;
+
+    private ToDTO from;
+
+    private List<ToDTO> replyTo;
+
+    private List<ToDTO> to;
+
+    private List<ToDTO> cc;
+
+    private List<ToDTO> bcc;
+
+    // private String raw;
+
+    private String subject;
+
+    // private String text;
+
+    private String html;
+
+    // private String previewText;
+
+    // private String template;
+
+    // private RenderDTO render;
+
+    private List<AttachmentsDTO> attachments;
+
+    // private String messageId;
+    //
+    // private Boolean trackingEnabled;
+    //
+    // private Object copy;
+    //
+    // private String sentMailPath;
+    //
+    // private String locale;
+    //
+    // private String tz;
+    //
+    // private String sendAt;
+    //
+    // private Integer deliveryAttempts;
+    //
+    // private String gateway;
+    //
+    // private String listId;
+    //
+    // private Boolean dryRun;
+
+    // @Data
+    // public static class ReferenceDTO {
+    //
+    //     private String message;
+    //
+    //     private String action;
+    //
+    //     private Boolean inline;
+    //
+    //     private Boolean forwardAttachments;
+    //
+    //     private Boolean ignoreMissing;
+    //
+    //     private Boolean documentStore;
+    // }
+
+    @Data
+    public static class ToDTO {
+        private String name;
+        private String address;
+    }
+
+    // @Data
+    // public static class RenderDTO {
+    //     private String format;
+    //
+    // }
+
+    @Data
+    public static class AttachmentsDTO {
+
+        private String filename;
+
+        private String contentType;
+
+        private String content;
+
+    }
+
+}