Browse Source

[BI]寄送訊息API 追加寄送Email邏輯

jeff 3 months ago
parent
commit
a7bbefecf8

+ 56 - 26
TEAMModelBI/ClientApp/src/view/systemConfig/NewMsg/active/test.vue

@@ -1,36 +1,66 @@
 <template>
-    <div style="text-align:left;padding-left:20px;">
-        <el-radio-group v-model="radio1" size="large">
-            <el-radio-button label="模版一" value="New York" />
-            <el-radio-button label="模版二" value="Washington" />
-        </el-radio-group>
-    </div>
-
-    <div v-if="radio1=='模版一'">
-        模版一
-    </div>
-
-    <div v-if="radio1=='模版二'">
-        模版二
-    </div>
-   
+    <el-form ref="formEl" :model="formData" :rules="rules">
+        <el-form-item label="主旨" prop="sub">
+            <el-input v-model="formData.sub"></el-input>
+        </el-form-item>
+        <el-form-item label="標題" prop="title">
+            <el-input v-model="formData.title"></el-input>
+        </el-form-item>
+        <el-form-item label="內容" prop="body">
+            <el-input v-model="formData.body"></el-input>
+        </el-form-item>
+        <el-button @click="handleSubmit">提交</el-button>
+    </el-form>
 </template>
 
 <script setup>
+    import { ref } from 'vue';
+    import { ElMessage } from 'element-plus';
 
-    import { ref } from 'vue'
+    // 定義表單模型
+    const formData = ref({
+        sub: '',
+        title: '',
+        body: ''
+    });
 
-    const radio1 = ref('模版一')
-    
-</script>
+    // 定義驗證規則
+    const rules = {
+        sub: [{ required: true, message: '請填寫主旨', trigger: 'blur' }],
+        title: [{ required: true, message: '請填寫標題', trigger: 'blur' }],
+        body: [{ required: true, message: '請填寫內容', trigger: 'blur' }]
+    };
 
-<style scoped>
+    // 定義表單元素引用
+    const formEl = ref(null);
 
-    /* 自定義 el-radio-button 大小*/
-    :deep(.el-radio-button--large .el-radio-button__inner) {
-        padding: 10px 20px;
-        font-size: 14px;
-        width: 200px;
+    // 表單驗證函式
+    function validateForm(formEl) {
+        return new Promise((resolve, reject) => {
+            if (!formEl) return reject("表單元素不存在");
+
+            formEl.validate((valid) => {
+                if (valid) {
+                    resolve(true);  // 驗證成功
+                } else {
+                    reject("表單驗證失敗,請檢查錯誤");
+                }
+            });
+        });
     }
 
-</style>
+    // 提交表單
+    async function handleSubmit() {
+        try {
+            // 等待表單驗證
+            await validateForm(formEl.value);
+
+            // 驗證成功後,進行其他操作(例如 API 請求)
+            ElMessage.success("表單提交成功!");
+            // 在這裡可以處理實際的提交操作
+        } catch (error) {
+            // 如果驗證失敗,顯示錯誤訊息
+            ElMessage.error(error);
+        }
+    }
+</script>

+ 4 - 1
TEAMModelBI/ClientApp/src/view/systemConfig/NewMsg/geos_info_id.vue

@@ -122,6 +122,9 @@
     // 从父组件注入的接收名单和更新方法
     const column3Items = inject("column3Items", ref([])); // 接收名單
 
+    // 取得站台資訊
+    let new_msg_station = inject('new_msg_station');   // 站台資訊: CN or ORG
+
     // 通知類型
     //"type": "notify", //發送類型 mail:郵件、notify:端外、sms:簡訊
     const notifyType = inject("notifyType");
@@ -242,7 +245,7 @@
         column3Items.value.splice(index, 1);
     };
 
-    let new_msg_station = "";
+    //let new_msg_station = "";
     // 一開始加載時,获取地理资讯数据
     const fetchData = async () => {
 

+ 3 - 40
TEAMModelBI/ClientApp/src/view/systemConfig/NewMsg/index.vue

@@ -57,7 +57,7 @@
             <Active_Test active="active" @update-active="updateActive" />
         </div>
 
-        <span style="display: none; font-size: 10px; line-height: 1.2; text-align: left;">
+        <span style="display: in; font-size: 10px; line-height: 1.2; text-align: left;">
             <el-button @click="mytest">測試</el-button>
         </span>
 
@@ -107,44 +107,7 @@
     // 提供給子組件
     provide('messageData', messageData);
 
-    const messageDemo = ref({
-        target: {
-            area: ["02944f32-f534-3397-ea56-e6f1fc6c3714"],
-            geo: [
-                {
-                    countryId: "TW",
-                    provinceId: null,
-                    cityId: "30",
-                    type: "school",
-                },
-            ],
-            unit: ["1", "2"],
-            school: ["habook", "hbgl"],
-            tmid: ["1522758684", "1595321354"],
-        },
-        type: "notify",
-        method: "multi",
-        subject: "主題",
-        title: "BI寄送訊息測試",
-        body: "這是系統寄送訊息的測試內容,旨在確認訊息傳遞是否正常運作。",
-        sender: "IES",
-        hubName: "hita5",
-        data: JSON.stringify({
-            img: ["https://account.teammodel.net/img/teammodel_title_en.c4d8a10b.png"],
-            action: [
-                {
-                    type: "click",
-                    label: "醍摩豆",
-                    url: "https://www.habook.com/?code=",
-                    quickLogin: true,                    
-                },
-            ],
-        }),
-        template: "d-f1c5abd8218736783",
-        send: 1736215236,
-    });
-
-
+    
     // 取得服務 url
     const new_msg_host = ref("");
     // 在组件挂载时获取 window.location.host
@@ -156,7 +119,7 @@
     // 定义 active 变量并设定初始值
     const active = ref(0);
 
-    // 批量或個別:  single:個別 multi:批次
+    //挑選方式 single:個別 multi:批次
     const selectionType = ref('multi');
     provide("selectionType", selectionType);
 

+ 127 - 20
TEAMModelBI/ClientApp/src/view/systemConfig/NewMsg/new_msg_EditEmail.vue

@@ -6,15 +6,19 @@
         <el-tag size="large" type="info" effect="light" style="margin:20px;">Email通知</el-tag>
 
         <div style="text-align: left; padding-left: 20px; display: flex; flex-direction: column; align-items: flex-start;">
-            <el-radio-group v-model="radio1" size="large">
-                <el-radio-button label="模版一" value="New York" />
-                <el-radio-button label="模版二" value="Washington" />
+            <el-radio-group v-model="template" size="large">
+                <el-radio-button label="d-f1c5abd8218736783">
+                    模版一
+                </el-radio-button>
+                <el-radio-button label="template2">
+                    模版二
+                </el-radio-button>
             </el-radio-group>
         </div>
     </div>
 
     <!-- 模版一-->
-    <div style="padding-bottom:10px;background-color: #FFFFFF; /* 背景白色 */" v-if="radio1==='模版一'">
+    <div style="padding-bottom:10px;background-color: #FFFFFF; /* 背景白色 */">
 
         <el-form ref="ruleFormRef" :model="noticeForm" :rules="rules" label-width="120px" style="gap: 210px;">
 
@@ -128,14 +132,14 @@
     </div>
 
     <!-- 模版二-->
-    <div style="padding-bottom:10px;background-color: #FFFFFF; /* 背景白色 */" v-if="radio1==='模版二'">
+    <div style="padding-bottom:10px;background-color: #FFFFFF; /* 背景白色 */" v-if="template==='不顯示'">
         模版二
     </div>
 
     <!-- 上一步,發送,重置-->
     <el-button type="primary" @click="goPreviousStep">上一步</el-button>
     <!--el-button type="primary" @click="submitForm(ruleFormRef)" :loading="loading">發送</!--el-button> -->
-    <el-button type="primary" @click="sendMessage" :loading="loading">發送</el-button>
+    <el-button type="primary" @click="handleSubmit" :loading="loading">發送</el-button>
     <el-button @click="resetForm(ruleFormRef)" :loading="loading">重置</el-button>
 
 
@@ -144,19 +148,28 @@
 <script setup>
     import { reactive, ref, computed, getCurrentInstance, markRaw, inject, watch } from 'vue'
     import { Warning, SuccessFilled, Plus, Close } from '@element-plus/icons'
-    import { ElMessageBox } from 'element-plus'
+    import { ElMessageBox, ElMessage } from 'element-plus'
     import { onMounted } from '../../../../node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler'
     let { proxy } = getCurrentInstance()
 
-    const radio1 = ref('模版一')
+
+    const template = ref('d-f1c5abd8218736783')
 
     //標題和內容
     const new_msg_title = inject('new_msg_title');
     const new_msg_body = inject('new_msg_body');
 
     // 从父组件注入的接收名单和更新方法
+    const selectionType = inject('selectionType'); 
+
     const column3Items = inject("column3Items", ref([])); // 接收名單
 
+    //"type": "notify", //發送類型 mail:郵件、notify:端外、sms:簡訊
+    const notifyType = inject('notifyType'); 
+
+    // 取得站台資訊
+    let new_msg_station = inject('new_msg_station');   // 站台資訊: CN or ORG
+
     // 定义触发事件的方式,emit 会用来触发更新 active 的事件
     const emit = defineEmits();
 
@@ -211,6 +224,39 @@
         noticeForm.data.img = FakeData.value.image ? [FakeData.value.image]:[];
     };
 
+    // 表單驗證函式
+    function validateForm(formEl) {
+        return new Promise((resolve, reject) => {
+            if (!formEl) return reject("表單元素不存在");
+
+            formEl.validate((valid) => {
+                if (valid) {
+                    resolve(true);  // 驗證成功
+                } else {
+                    reject("表單驗證失敗,請檢查錯誤");
+                }
+            });
+        });
+    }
+
+    // 提交表單
+    async function handleSubmit() {
+        try {
+            // 等待表單驗證
+            await validateForm(ruleFormRef.value);
+
+            // 驗證成功後,進行其他操作(例如 API 請求)
+            //ElMessage.success("表單提交成功!");
+            // 在這裡可以處理實際的提交操作
+            
+            await sendMessage();
+
+
+        } catch (error) {
+            // 如果驗證失敗,顯示錯誤訊息
+            ElMessage.error(error);
+        }
+    }
 
 
     // 儲存 標題
@@ -500,18 +546,53 @@
         }
     }
 
+    const requestData = ref({
+        target: {
+            area: [],
+            geo: [],
+            unit: [],
+            school: [],
+            tmid: [],
+        },
+        type: "",        // 發送類型        
+        method: "",      //挑選方式 single:個別 multi:批次
+        title: "",       // 標題
+        body: "",        // 內文
+        sender: "",      // 訊息發送來源
+        hubName: "",     // 訊息中樞
+        data: "",        // 序列化資料
+        //data: {
+        //    img: [
+        //        "https://account.teammodel.net/img/teammodel_title_en.c4d8a10b.png"
+        //    ],
+        //    action: [
+        //        {
+        //            type: "click",
+        //            label: "醍摩豆",
+        //            url: "https://www.habook.com/?code=",
+        //            quickLogin: true,
+        //            quicklogin: 1
+        //        }
+        //    ]
+        //},
+        //template: "",    // 模板ID : Email 用
+        send: 0,         // 發送時間,預設 0
+    });
+
     // 發送訊息 (新)
     const sendMessage = async () => {
-
-        //ElMessage("Hi, Buddy~!");
-
+    //const sendMessage =  () => {
+    
         //填入資料
 
         // // 發送類型  type : "notify", //發送類型 mail:郵件、notify:端外、sms:簡訊
-        requestData.value.type = notifyType;
+        requestData.value.type = notifyType.value;
 
         //挑選方式 single:個別 multi:批次
-        requestData.value.method = selectionType;
+        requestData.value.method = selectionType.value;
+
+        // sub 主旨
+        requestData.value.sub = noticeForm.sub;
 
         // 標題
         requestData.value.title = new_msg_title;
@@ -519,8 +600,26 @@
         // 內文
         requestData.value.body = new_msg_body;
 
-        //附加按鈕 非必須
-        requestData.value.action = new_msg_action;
+        // 開始發送訊息
+        console.log('開始發送訊息...');
+        
+        //data 空值判斷  (圖片)
+
+        const { img, action } = noticeForm.data;
+        let result = {};
+        if (img?.[0] !== "") {
+            result.img = img;
+        }
+
+        // 都為空字串,則設空字串
+        if (img?.[0] === "") {
+            requestData.value.data = "";
+        } else {
+            requestData.value.data = JSON.stringify(result); // 序列化成 JSON 字串
+        }
+
+        // 發送者
+        requestData.value.sender = noticeForm.sender;
 
         // target
         // area, geo, unit, school, tmid
@@ -532,7 +631,7 @@
         const listSchool = [];
         const listUnit = [];
         const listTmid = [];
-        //debugger;
+
         // 取值
         for (const item of column3Items.value) {
 
@@ -629,9 +728,9 @@
         }
 
 
-        //debugger;
+        debugger;
 
-        if (0) {
+        if (1) {
 
             // 傳送訊訊
             proxy.$api.sendMessage(requestData.value).then((res) => {
@@ -655,9 +754,17 @@
 
         }
 
+        if (1) {
+            // 回到首頁
+            emit('update-active', 0); // 通知父组件更新 active 的值为 0
+
+            // 清空接收名單
+            column3Items.value = []
 
-        // 回到發送歷程
-        //goMsgHistory()
+
+            // 回到發送歷程
+            //goMsgHistory()
+        }
     };
 
 

+ 61 - 25
TEAMModelBI/ClientApp/src/view/systemConfig/NewMsg/new_msg_EditMsg.vue

@@ -125,9 +125,14 @@
     import { ElMessageBox, ElMessage } from 'element-plus'
     let { proxy } = getCurrentInstance()
 
+    const template = ref('')
+
     // 接收父組件提供的 messageData
     const messageData = inject('messageData');
 
+    // 取得站台資訊
+    let new_msg_station = inject('new_msg_station');   // 站台資訊: CN or ORG
+
     //發送時間
     const new_msg_send = inject('new_msg_send');
 
@@ -517,28 +522,61 @@
     // 定義發送請求的參數  (名單部分沒有變)
 
 
+    //const requestData = ref({
+    //    target: {
+    //        area: ["02944f32-f534-3397-ea56-e6f1fc6c3714"],
+    //        geo: [
+    //            {
+    //                countryId: "TW",
+    //                provinceId: null,
+    //                cityId: "30",
+    //                type: "school",
+    //            },
+    //        ],
+    //        unit: ["1", "2"],
+    //        school: ["habook", "hbgl"],
+    //        tmid: ["1522758684", "1595321354"],
+    //    },
+    //    type: "notify", // 發送類型
+    //    method: "multi", // 挑選方式
+    //    title: "BI寄送訊息測試", // 標題
+    //    body: "這是系統寄送訊息的測試內容,旨在確認訊息傳遞是否正常運作。", // 內文
+    //    sender: "IES", // 訊息發送來源
+    //    hubName: "hita5", // 訊息中樞
+    //    data: "",    // data 要序例化成 json 字串
+    //    //data: {
+    //    //    img: [
+    //    //        "https://account.teammodel.net/img/teammodel_title_en.c4d8a10b.png"
+    //    //    ],
+    //    //    action: [
+    //    //        {
+    //    //            type: "click",
+    //    //            label: "醍摩豆",
+    //    //            url: "https://www.habook.com/?code=",
+    //    //            quickLogin: true,
+    //    //            quicklogin: 1
+    //    //        }
+    //    //    ]
+    //    //},
+    //    template: "d-f1c5abd8218736783", // 模板ID
+    //    send: 0, // 發送時間,0 表示立即發送
+    //});
+
     const requestData = ref({
         target: {
-            area: ["02944f32-f534-3397-ea56-e6f1fc6c3714"],
-            geo: [
-                {
-                    countryId: "TW",
-                    provinceId: null,
-                    cityId: "30",
-                    type: "school",
-                },
-            ],
-            unit: ["1", "2"],
-            school: ["habook", "hbgl"],
-            tmid: ["1522758684", "1595321354"],
+            area: [],
+            geo: [],
+            unit: [],
+            school: [],
+            tmid: [],
         },
-        type: "notify", // 發送類型
-        method: "multi", // 挑選方式
-        title: "BI寄送訊息測試", // 標題
-        body: "這是系統寄送訊息的測試內容,旨在確認訊息傳遞是否正常運作。", // 內文
-        sender: "IES", // 訊息發送來源
-        hubName: "hita5", // 訊息中樞
-        data: "",    // data 要序例化成 json 字串
+        type: "",        // 發送類型
+        method: "",      // 挑選方式
+        title: "",       // 標題
+        body: "",        // 內文
+        sender: "",      // 訊息發送來源
+        hubName: "",     // 訊息中樞
+        data: "",        // 序列化資料
         //data: {
         //    img: [
         //        "https://account.teammodel.net/img/teammodel_title_en.c4d8a10b.png"
@@ -553,15 +591,13 @@
         //        }
         //    ]
         //},
-        template: "d-f1c5abd8218736783", // 模板ID
-        send: 0, // 發送時間,0 表示立即發送
+        //template: "",    // 模板ID : Email 用
+        send: 0,         // 發送時間,預設 0
     });
 
     // 發送訊息 (新)
     const sendMessage = async () => {
-
-        //ElMessage("Hi, Buddy~!");
-
+                
         //填入資料
 
         // // 發送類型  type : "notify", //發送類型 mail:郵件、notify:端外、sms:簡訊
@@ -576,7 +612,7 @@
         // 內文
         requestData.value.body = new_msg_body;
     
-        //data 空值判斷
+        //data 空值判斷  (圖片,按鈕)
 
         const { img, action } = noticeForm.data;
         let result = {};

+ 3 - 3
TEAMModelBI/ClientApp/src/view/systemConfig/NewMsg/new_msg_Type.vue

@@ -9,7 +9,7 @@
 
             <el-radio-group v-model="notifyType" style="margin-top: 20px;">
                 <el-radio label="notify">端外通知</el-radio>
-                <el-radio label="mail" disabled >Email</el-radio>
+                <el-radio label="mail" >Email</el-radio>
                 <el-radio label="sms" disabled>簡訊</el-radio>
             </el-radio-group>
 
@@ -51,8 +51,8 @@
     //"type": "notify", //發送類型 mail:郵件、notify:端外、sms:簡訊
     const notifyType = inject('notifyType');
 
-    //notifyType.value = 'mail';
-    notifyType.value = 'notify';
+    notifyType.value = 'mail';
+    //notifyType.value = 'notify';
    
     // 定义父组件传递过来的 props
     const props = defineProps({

+ 65 - 25
TEAMModelBI/Controllers/BICommon/BINoticeController.cs

@@ -39,6 +39,9 @@ using MathNet.Numerics.Distributions;
 using System.Drawing.Drawing2D;
 using Microsoft.Azure.Amqp.Framing;
 using TEAMModelOS.SDK.DI.IPIP;
+using Azure;
+using Microsoft.AspNetCore.Http.HttpResults;
+using System.Net;
 
 
 namespace TEAMModelBI.Controllers.BICommon
@@ -1238,8 +1241,16 @@ namespace TEAMModelBI.Controllers.BICommon
             string data = (jsonElement.TryGetProperty("data", out JsonElement _data)) ? _data.ToString() : string.Empty; //額外資料
             long send = (jsonElement.TryGetProperty("send", out JsonElement _send)) ? _send.GetInt64() : 0; //發送時間 0:立即發送
             string template = (jsonElement.TryGetProperty("template", out JsonElement _template)) ? _template.ToString() : string.Empty; //模板ID
-
-            if (target == null || string.IsNullOrWhiteSpace(type) || string.IsNullOrWhiteSpace(method) || string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(body) || string.IsNullOrWhiteSpace(sender)) return BadRequest();
+            //必須項檢驗
+            if (target == null || string.IsNullOrWhiteSpace(type) || string.IsNullOrWhiteSpace(method) || string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(body)) return BadRequest();
+            if(type.Equals("notify"))
+            {
+                if(string.IsNullOrWhiteSpace(sender)) return BadRequest();
+            }
+            else if(type.Equals("mail"))
+            {
+                if (string.IsNullOrWhiteSpace(subject)) return BadRequest();
+            }
             string eventKey = "bi-gen-notify";
             string eventId = $"{eventKey}_{_snowflakeId.NextId()}";
             string eventName = "BI send notification";
@@ -1298,7 +1309,7 @@ namespace TEAMModelBI.Controllers.BICommon
             tmids = tmids.Union(tmids_direct).ToList();
             tmids = tmids.Distinct().ToList();  //唯一化
 #if DEBUG //測試模式時限制TMID帳號,正式站佈署時不生效
-            List<string> filterTmid = new List<string>() { "1522758684", "1595321354" };
+            List<string> filterTmid = new List<string>() { "1522758684" }; //"1522758684", "1595321354"
             tmids = tmids.Intersect(filterTmid).ToList();
 #endif
 
@@ -1336,7 +1347,7 @@ namespace TEAMModelBI.Controllers.BICommon
                     //寄送訊息DB記入
                     if(response.IsSuccessStatusCode)
                     {
-                        BINotice bINotice = TransMsgRequestToBINotice("notify", method, subject, title, body, sender, hubName, target, tmIds, data);
+                        BINotice bINotice = TransMsgRequestToBINotice(type, method, subject, title, body, sender, hubName, target, tmIds, data);
                         bINotice.id = Guid.NewGuid().ToString();
                         bINotice.createId = _tmdId;
                         bINotice.sendTime = (send.Equals(0)) ? DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() : send; //先處理"及時寄送","定時寄送"待處理
@@ -1354,30 +1365,58 @@ namespace TEAMModelBI.Controllers.BICommon
             }
             else if(type.Equals("mail")) //Email
             {
-                string defaultTemplate = "d-f1c5abd8247f4be79ceaecdd327e9a68";
+                string defaultTemplate = "d-f1c5abd8247f4be79ceaecdd327e9a68"; //國際站預設模板 ※CN站還沒有
+                List<string> mailList = tmidInfos.Where(i => !string.IsNullOrWhiteSpace(i.mail)).Select(i => i.mail).ToList();
                 List<string> tmIds = tmidInfos.Where(i => !string.IsNullOrWhiteSpace(i.mail)).Select(i => i.id).ToList();
                 //呼叫Email API [未]
                 ///模板設定
-                if(_option.Location.Contains("Global"))
+                if (_option.Location.Contains("Global"))
                 {
                     if (string.IsNullOrWhiteSpace(template))
                         template = defaultTemplate; //若未指定模板ID,用預設模板
                 }
-
+                if(string.IsNullOrWhiteSpace(template)) //無模板ID,就不執行
+                {
+                    var result = new { status = HttpStatusCode.BadRequest };
+                    return result;
+                }
                 //Email寄送
-                HttpResponseMessage response = CallPushNotifyApi(tmIds, title, body, sender, hubName, template, data, eventId, eventName);
-                //寄送訊息DB記入
-                if (response.IsSuccessStatusCode)
+                bool sendMail = false;
+                if (send.Equals(0)) //立即寄送
                 {
-                    BINotice bINotice = TransMsgRequestToBINotice("notify", method, subject, title, body, sender, hubName, target, tmIds, data);
-                    bINotice.id = Guid.NewGuid().ToString();
-                    bINotice.createId = _tmdId;
-                    bINotice.sendTime = (send.Equals(0)) ? DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() : send; //先處理"及時寄送","定時寄送"待處理
-                    await cosmosClientIes.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync<BINotice>(bINotice, new PartitionKey("BINotice"));
+                    List<string> imgArr = new List<string>();
+                    try
+                    {
+                        JsonElement dataJobj = JsonSerializer.Deserialize<JsonElement>(data);
+                        if(dataJobj.TryGetProperty("img", out JsonElement _img))
+                        {
+                            imgArr = _img.ToObject<List<string>>();
+                        }
+                    }
+                    catch (JsonException) { }
+                    string image = (imgArr.Count > 0) ? imgArr[0] : string.Empty;
+                    foreach(string email in mailList)
+                    {
+                        await CallSendMailApiAsync(email, subject, title, body, template, image);
+                        sendMail = true;
+                    }
+                    //寄送訊息DB記入
+                    if (sendMail)
+                    {
+                        BINotice bINotice = TransMsgRequestToBINotice(type, method, subject, title, body, sender, hubName, target, tmIds, data);
+                        bINotice.id = Guid.NewGuid().ToString();
+                        bINotice.createId = _tmdId;
+                        bINotice.sendTime = (send.Equals(0)) ? DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() : send; //先處理"及時寄送","定時寄送"待處理
+                        await cosmosClientIes.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync<BINotice>(bINotice, new PartitionKey("BINotice"));
+                    }
+
+                    var result = new { status = HttpStatusCode.OK, content = string.Empty };
+                    return result;
                 }
+                else //定時寄送 [待做]
+                {
 
-                var result = new { };
-                return result;
+                }
             }
             else if (type.Equals("sms")) //短訊
             {
@@ -1612,15 +1651,16 @@ namespace TEAMModelBI.Controllers.BICommon
             return responseMessage;
         }
 
-        private HttpResponseMessage CallSendMailApi(List<string> tmIds, string subject, string title, string body, string template, string data, string eventId = "", string eventName = "")
+        private async Task CallSendMailApiAsync(string email, string subject, string title, string body, string template, string image)
         {
-            //{
-            //    "sub":"a",
-            //    "title":"嘿嘿",
-            //    "body":"見鬼拉",
-            //    "image":"https://corestorageservice.blob.core.windows.net/public-marketing/S__43540491.png"
-
-            //}
+            object mailVars = new
+            {
+                sub = subject,
+                title = title,
+                body = body,
+                image = image
+            };
+            await _coreAPIHttpService.SendMail(new Dictionary<string, object> { { "to", email }, { "tid", template }, { "vars", mailVars } }, _option.Location, _configuration);
         }
 
         /// <summary>