wzp
2021-05-13 7d694a9113118daec5be7ac224dab46a3b20f106
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
var {searchPool}=require("./mail/poolmgr")
var {addTemplate,addTemplateFile}=require("./mail/templ")
 
 
var {addTask,startSendEmail,getTaskList,getTaskReport,getTrack,getTrackAsync} = require("./mail/task")
 
var fs=require("fs")
var FullName="王立忠";
var Company='广州德鲁伊信息科技';
var url="https://test.tai-online.com";
var content=`
Dear ${FullName},<br><br>
 
You've been invited to take an assessment from ${Company}. Please use the link below to begin the assessment.<br><br>
 
You may either click the link below directly, or copy and paste the link to your browser. <br><br>
 
Link: <a href='${url}' target='_blank'>${url}</a><br><br>
 
Should you have problem assessing the above link, please contact our customer service at fanjinyan@yahoo.com.<br><br>
 
All the best,<br><br>
 
${Company}<br><br>
 
亲爱的${FullName},<br><br>
 
${Company}邀请您完成一份网上测试。您可以直接点击下面的链接开始该测试。如果不能直接访问,请复制地址到浏览器中直接打开。链接地址是:<br><br>
 
Link: <a href='${url}' target='_blank'>${url}</a><br><br>
 
如有疑问,请与客服联系,邮箱是:fanjinyan@yahoo.com<br><br>
 
谢谢!<br><br>
 
${Company}`
 
function send(username,toemail,title,content,callbackFunc,errCallBack){
    searchPool(toemail,username,function(poolId){
        console.log("找到地址池",poolId);
            addTemplate(title,content,function(tempId){
                addTask(tempId,poolId,title,function(taskId){
                    startSendEmail(taskId,callbackFunc,errCallBack);
                },errCallBack)
        },errCallBack);
    },errCallBack);
    
}
function sendAsync(username,toemail,title,content){
    return new Promise(function (resolve, reject) {
        send(username,toemail,title,content,function(e){
            resolve(e);
        },function(e){
            reject(e);
        })
    });
}
/**
 * 发送邮件带附件
 * @param {string} username  收件人名称
 * @param {string} title  邮件标题
 * @param {*} toemail  收件人邮箱
 * @param {*} content 发送内容,支持html
 * @param {string|Array} attachment  附件或附件列表
 */
function sendWidthAttachment(username,toemail,title,content,attachment,callbackFunc,errCallFunc){
    var atts=[];
    if(attachment instanceof Array){
        for(var att of attachment){
            if(!fs.existsSync(att)){
                // console.log("文件不存在!",att);
                if(errCallFunc){
                    errCallFunc("文件不存在!"+att)
                }
                return false;
            }
        }
        atts=attachment;
    }else{
        if(!fs.existsSync(attachment)){
            // console.log("文件不存在",attachment);
            if(errCallFunc){
                errCallFunc("文件不存在!"+attachment)
            }
            return false;
        }
        atts=[attachment]
    }
 
    searchPool(toemail,username,function(poolId){
        console.log("找到地址池",poolId);
            addTemplate(title,content,function(tempId){
                addTemplateFile(tempId,atts,function(e){
                    addTask(tempId,poolId,title,function(taskId){
                        startSendEmail(taskId,function(ret){
                                if(callbackFunc)
                                    callbackFunc(ret);
                        },errCallFunc);
                    },errCallFunc)
                },errCallFunc);
               
        },errCallFunc);
    },errCallFunc)
}
/**
 * 发送邮件,带附件
 * @param {*} username 
 * @param {*} toemail 
 * @param {*} content 
 * @param {*} attachment 
 * @returns 返回taskid
 */
var sendWidthAttachmentAsync=async function(username,toemail,title,content,attachment){
    return new Promise(function (resolve, reject) {
        sendWidthAttachment(username,toemail,title,content,attachment, function (ret) {
            resolve(ret);
        }, function (e) {
            reject(e)
        });
 
    })
exports.sendAsync=sendAsync;
exports.sendWidthAttachmentAsync = sendWidthAttachmentAsync;
// send("王立忠","66905212@sohu.com",content);//,"C:/Users/Administrator/Downloads/Rushmail邮件群发平台API接口文档(2).pdf");
// addTemplteFile(94924,"C:/Users/Administrator/Downloads/Rushmail邮件群发平台API接口文档(2).pdf")
// getTaskList(function(e){
//     for(var task of e){
//         var task_id=task.task_id;
//         var template_id=task.template_id;
//         var pool_id=task.pool_id;
//         var task_name=task.task_name;
//         var count_preset=task.count_preset;
//         var count_send = task.count_send;
//         var time_preset = task.time_preset;
//         var time_start = task.time_preset;
//         var email_did = task.email_did;
//         var email_id = task.email_id;
//         var email_addr = task.email_addr;
//         var reply_to = task.reply_to;
//         var track = task.track;
//         var status = task.status;
//         var examine=task.examine;
//         console.log(task)
//         // if(task_id==249282){
//         //     console.log(task)
//         // }
//         // if(status==2 && examine==1){
//         //     console.log(task)
//         // }
        
 
//     }
// })
function getFailType(task){
    if(task.failure3_count>0)return 3;
    if(task.failure2_count>0)return 2;
    if(task.failure1_count>0)return 1;
    return 0;
}
 
 
var main=async function(){
    
getTaskReport("2020-6-16",async function(ret){
    // console.log(ret);
    var tasklist=[];
    for(var task of ret){
        var fail=getFailType(task);
        var wctask_id=task.wctask_id;
        if(fail ==0 && wctask_id>0){
            console.log(wctask_id)
           var trackInfo= await getTrackAsync(wctask_id);
          
        }
        var t={task_id:task.task_id,sent:task.receive_count,fail:fail}
        tasklist.push(t);
       
    }
   
   
})
    // var ret=await getTrackAsync(249286)
    // console.log(ret)
 
//   sendWidthAttachmentAsync("王立忠","66905212@qq.com",content,"C:/Users/Adinistrator/Downloads/Rushmail邮件群发平台API接口文档(2).pdf").then((e)=>{
//     console.log("11"+e)
//   }).catch((e)=>{
//       console.log(e)
//   })
 
}
// main();
// addTemplateFile(94923,["G:\\project\\互联网项目\\testtaker\\图片8.png"],function(e){
//     console.log("上传成功")
// });