notificationemail
This commit is contained in:
		| @@ -256,7 +256,7 @@ Notifications.manageemail = async (data, templatename, tribe, lg,numberpersecond | |||||||
|       data: data, |       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`; |   const tplpath = `../${tribe}/template/${templatename}_${lg}.js`; | ||||||
|   if (!fs.existsSync(tplpath)) { |   if (!fs.existsSync(tplpath)) { | ||||||
|     return { |     return { | ||||||
| @@ -277,10 +277,23 @@ Notifications.manageemail = async (data, templatename, tribe, lg,numberpersecond | |||||||
|  |  | ||||||
|   for (let i = 0; i < data.emailsto.length; i++) { |   for (let i = 0; i < data.emailsto.length; i++) { | ||||||
|     const email = data.emailsto[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(); |     emailtosend.to = email.to.toLowerCase().trim(); | ||||||
|     if (!Checkjson.testformat(emailtosend.to, "email")) { |     if (emailtosend.to.length>2) { | ||||||
|       results.fail.push({ to: emailtosend.to, err: ["errorformat"] }); |       emailtosend.to=emailtosend.to.slice(0,-1); | ||||||
|     } else { |  | ||||||
|       emailtosend.templatename=templatename; |       emailtosend.templatename=templatename; | ||||||
|       emailtosend.lg=lg |       emailtosend.lg=lg | ||||||
|       emailtosend.subject = Mustache.render(tplemail.subject, email); |       emailtosend.subject = Mustache.render(tplemail.subject, email); | ||||||
| @@ -304,7 +317,7 @@ Notifications.manageemail = async (data, templatename, tribe, lg,numberpersecond | |||||||
|       if (sendit.status == 200) { |       if (sendit.status == 200) { | ||||||
|         results.success.push(emailtosend.to); |         results.success.push(emailtosend.to); | ||||||
|       } else { |       } else { | ||||||
|         results.fail.push({ tp: emailtosend.to, status: sendit.status }); |         results.fail.push({ to: emailtosend.to, status: sendit.status }); | ||||||
|         console.log(sendit) |         console.log(sendit) | ||||||
|       } |       } | ||||||
|       if ((i + 1) % numberpersecond === 0) { |       if ((i + 1) % numberpersecond === 0) { | ||||||
| @@ -319,8 +332,8 @@ Notifications.manageemail = async (data, templatename, tribe, lg,numberpersecond | |||||||
|   ); |   ); | ||||||
|   return { |   return { | ||||||
|     status: 200, |     status: 200, | ||||||
|     ref: "Wwws", |     ref: "Notifications", | ||||||
|     msg: "campainsent", |     msg: "emailmanage", | ||||||
|     data: { |     data: { | ||||||
|       emailsucces: results.success.length, |       emailsucces: results.success.length, | ||||||
|       emailfail: results.fail.length, |       emailfail: results.fail.length, | ||||||
|   | |||||||
| @@ -58,16 +58,15 @@ router.get("/messages/:alias/:tribeId", (req, res) => { | |||||||
|  |  | ||||||
|  * @apiGroup Notifications |  * @apiGroup Notifications | ||||||
|  * |  * | ||||||
|  * @apiParam {string} template |  * @apiParam {string} template that must exist in {tribe}/template/{template}_{lg}.js that contain all email component (html, text, attachement...) | ||||||
|  * @apiParam {string} tribe  |  * @apiParam {string} tribe  | ||||||
|  * @apiBody {array} emails to send (array of valid email) |  * @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}] | ||||||
|  * @apiBody {object} data to personnalize template |  *   | ||||||
|  * |  * | ||||||
|  * @apiSuccess {object}  notif content |  * @apiSuccess {object}  notif content | ||||||
|  * @apiSuccessExample {json} Success-Response: |  * @apiSuccessExample {json} Success-Response: | ||||||
|  * HTTP/1.1 200 OK |  * HTTP/1.1 200 OK | ||||||
|  * {status:200,ref:"Notification",msg:"Messagelist",data:{notif:[{tribeId,msg:{from(email or uuid or alias):[{dt,msg}]}}]} |  * {status:200,ref:"Notification",msg:"emailmanage",data:{emailsuccess:"number of mail sent",emailfail:"number of email adresse rejected",failsdetail:[{to:emailerror,err:["errorformat"]}] | ||||||
|  * bouture |  | ||||||
|  */ |  */ | ||||||
| router.post( | router.post( | ||||||
|   "/sendmail/:tribe/:template", |   "/sendmail/:tribe/:template", | ||||||
| @@ -96,7 +95,7 @@ router.post( | |||||||
|       ); |       ); | ||||||
|       sendret = sendcampain; |       sendret = sendcampain; | ||||||
|     } else if (req.body.emails) { |     } 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 = { |       const campain = { | ||||||
|         emailsto: [ |         emailsto: [ | ||||||
|           { |           { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user