Skip to content

Commit 20b1348

Browse files
committed
feat: improve email sending process by sending individual messages to each recipient
- Refactored MailSendService to send a separate email for each recipient, ensuring better UI behavior in MailDev and similar SMTP services. - Updated the mail sending logic to loop through recipients, enhancing clarity and reliability in email delivery.
1 parent 007d6cc commit 20b1348

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

apps/api/src/management/mail/mail-send.service.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,24 @@ export class MailSendService {
144144
}
145145

146146
try {
147-
await this.mailer.sendMail({
148-
to: recipients.length === 1 ? recipients[0] : recipients,
149-
subject,
150-
template,
151-
context: {
152-
identity,
147+
// Envoyer un mail par destinataire.
148+
// MailDev (et certains SMTP) affichent souvent un seul message pour plusieurs RCPT TO ;
149+
// ici on force 1 message par adresse pour un comportement UI attendu.
150+
let sentForIdentity = 0;
151+
for (const to of recipients) {
152+
await this.mailer.sendMail({
153+
to,
153154
subject,
154-
...templateVariables,
155-
},
156-
});
157-
sent++;
155+
template,
156+
context: {
157+
identity,
158+
subject,
159+
...templateVariables,
160+
},
161+
});
162+
sentForIdentity++;
163+
}
164+
sent += sentForIdentity;
158165
} catch (e) {
159166
this.logger.warn(
160167
`Failed to send template <${template}> to identity <${(identity as any)?._id}>: ${e?.message || e}`,

0 commit comments

Comments
 (0)