notificationemail
This commit is contained in:
		| @@ -256,7 +256,7 @@ Notifications.manageemail = async (data, templatename, tribe, lg,numberpersecond | ||||
|       data: data, | ||||
|     }; | ||||
|   } | ||||
|   if (typeof data.emailsto === "string") data.emailsto = [data.emailsto]; | ||||
|   //if (typeof data.emailsto === "string") data.emailsto = [data.emailsto]; | ||||
|   const tplpath = `../${tribe}/template/${templatename}_${lg}.js`; | ||||
|   if (!fs.existsSync(tplpath)) { | ||||
|     return { | ||||
| @@ -277,10 +277,23 @@ Notifications.manageemail = async (data, templatename, tribe, lg,numberpersecond | ||||
|  | ||||
|   for (let i = 0; i < data.emailsto.length; i++) { | ||||
|     const email = data.emailsto[i]; | ||||
|     if (typeof email.to === "string"){ | ||||
|       email.to=[email.to] | ||||
|     } | ||||
|     emailtosend.to="" | ||||
|     email.to.forEach(em=>{ | ||||
|        em=em.toLowerCase().trim() | ||||
|        if (Checkjson.testformat(em, "email")){ | ||||
|         emailtosend.to+=em+"," | ||||
|        } | ||||
|        else { | ||||
|         results.fail.push({ to: em, err: ["errorformat"] }); | ||||
|        }     | ||||
|     }) | ||||
|      | ||||
|     emailtosend.to = email.to.toLowerCase().trim(); | ||||
|     if (!Checkjson.testformat(emailtosend.to, "email")) { | ||||
|       results.fail.push({ to: emailtosend.to, err: ["errorformat"] }); | ||||
|     } else { | ||||
|     if (emailtosend.to.length>2) { | ||||
|       emailtosend.to=emailtosend.to.slice(0,-1); | ||||
|       emailtosend.templatename=templatename; | ||||
|       emailtosend.lg=lg | ||||
|       emailtosend.subject = Mustache.render(tplemail.subject, email); | ||||
| @@ -304,7 +317,7 @@ Notifications.manageemail = async (data, templatename, tribe, lg,numberpersecond | ||||
|       if (sendit.status == 200) { | ||||
|         results.success.push(emailtosend.to); | ||||
|       } else { | ||||
|         results.fail.push({ tp: emailtosend.to, status: sendit.status }); | ||||
|         results.fail.push({ to: emailtosend.to, status: sendit.status }); | ||||
|         console.log(sendit) | ||||
|       } | ||||
|       if ((i + 1) % numberpersecond === 0) { | ||||
| @@ -319,8 +332,8 @@ Notifications.manageemail = async (data, templatename, tribe, lg,numberpersecond | ||||
|   ); | ||||
|   return { | ||||
|     status: 200, | ||||
|     ref: "Wwws", | ||||
|     msg: "campainsent", | ||||
|     ref: "Notifications", | ||||
|     msg: "emailmanage", | ||||
|     data: { | ||||
|       emailsucces: results.success.length, | ||||
|       emailfail: results.fail.length, | ||||
|   | ||||
| @@ -58,16 +58,15 @@ router.get("/messages/:alias/:tribeId", (req, res) => { | ||||
|  | ||||
|  * @apiGroup Notifications | ||||
|  * | ||||
|  * @apiParam {string} template | ||||
|  * @apiParam {string} tribe | ||||
|  * @apiBody {array} emails to send (array of valid email) | ||||
|  * @apiBody {object} data to personnalize template | ||||
|  * @apiParam {string} template that must exist in {tribe}/template/{template}_{lg}.js that contain all email component (html, text, attachement...) | ||||
|  * @apiParam {string} tribe  | ||||
|  * @apiBody {object} emailstosend {emailsto:[{to:[emailslist], cc:[],bcc:[],attachments:[] and any key:value specific for this email}], key:value common to all email that will be include in each email} each item af emailsto is a mail that will be send. If one email of emailsto[].to is not valid then it will be store in result.fail:[{to:emailerror,err:["errorformat"]}], then for well formùated email, the result of an email will be store in results.success:[{to:emailsto[].to.emailslist.join(","),status:smtp status}] | ||||
|  *   | ||||
|  * | ||||
|  * @apiSuccess {object}  notif content | ||||
|  * @apiSuccessExample {json} Success-Response: | ||||
|  * HTTP/1.1 200 OK | ||||
|  * {status:200,ref:"Notification",msg:"Messagelist",data:{notif:[{tribeId,msg:{from(email or uuid or alias):[{dt,msg}]}}]} | ||||
|  * bouture | ||||
|  * {status:200,ref:"Notification",msg:"emailmanage",data:{emailsuccess:"number of mail sent",emailfail:"number of email adresse rejected",failsdetail:[{to:emailerror,err:["errorformat"]}] | ||||
|  */ | ||||
| router.post( | ||||
|   "/sendmail/:tribe/:template", | ||||
| @@ -96,7 +95,7 @@ router.post( | ||||
|       ); | ||||
|       sendret = sendcampain; | ||||
|     } else if (req.body.emails) { | ||||
|       // To delete when Bhavesh removed direct email to send requesting registration | ||||
|       // To delete when Bhavesh removed direct email requesting registration | ||||
|       const campain = { | ||||
|         emailsto: [ | ||||
|           { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user