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},

You've been invited to take an assessment from ${Company}. Please use the link below to begin the assessment.

You may either click the link below directly, or copy and paste the link to your browser.

Link: ${url}

Should you have problem assessing the above link, please contact our customer service at fanjinyan@yahoo.com.

All the best,

${Company}

亲爱的${FullName},

${Company}邀请您完成一份网上测试。您可以直接点击下面的链接开始该测试。如果不能直接访问,请复制地址到浏览器中直接打开。链接地址是:

Link: ${url}

如有疑问,请与客服联系,邮箱是:fanjinyan@yahoo.com

谢谢!

${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("上传成功") // });