diff --git a/src/mailer/mailer.service.ts b/src/mailer/mailer.service.ts index 45bd33638ba0f05fe4a7bc99c17e0041675244d6..833908295aab54f1bcab9bbbb4d4e79f1056c9c9 100644 --- a/src/mailer/mailer.service.ts +++ b/src/mailer/mailer.service.ts @@ -37,7 +37,7 @@ export class MailerService { }) .subscribe( (body) => { - Logger.log(`Send mail - success : ${subject}`, 'Mailer'); + Logger.log(`Send mail to ${JSON.stringify(emailsToSend)} - success : ${subject}`, 'Mailer'); return resolve(body.data); }, (err) => { diff --git a/src/structures/services/structures.service.ts b/src/structures/services/structures.service.ts index c1642bc4ec3055e99890082c1f6f33ade28af6bb..fcd1595ff695529b5c866899ba71355734e28144 100644 --- a/src/structures/services/structures.service.ts +++ b/src/structures/services/structures.service.ts @@ -1442,12 +1442,18 @@ export class StructuresService { ownerList .filter((x) => x != undefined) .forEach(async (data) => { - this.userService.findOne(data.owner.email).then((user) => { + this.userService.findOne(data.owner.email).then(async (user) => { // If mail is already sent, do not resend if (user.structureOutdatedMailSent.includes(data.structure._id)) { return; } else { - this.sendOutdatedEmailToUser(data.owner.email, data.structure.structureName, data.structure._id); + try { + // Send mails sequentially because multiple simultaneous calls to send mail causes connect ETIMEDOUT error and container restart + await this.sendOutdatedEmailToUser(data.owner.email, data.structure.structureName, data.structure._id); + } catch (error) { + this.logger.error(`Couldn't send email to ${data.owner.email}. Error: ${error}`); + } + user.structureOutdatedMailSent.push(data.structure._id); user.save(); }