Skip to content

Commit dcf38b8

Browse files
committed
feat(mail-sending): randomize services
1 parent 627385e commit dcf38b8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/@deeplib/mail/src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { mainLogger } from '@stdlib/misc';
22

33
import { sendBrevoMail } from './brevo';
44
import { sendMailjetMail } from './mailjet';
5-
import { sendSendGridMail } from './send-grid';
65

76
export { sendBrevoMail } from './brevo';
87
export { sendMailjetMail } from './mailjet';
@@ -18,15 +17,18 @@ export interface MailOptions {
1817
export type MailSendFunc = (opts: MailOptions) => Promise<void>;
1918

2019
const _sendMailFuncs: [string, MailSendFunc][] = [
21-
['SendGrid', sendSendGridMail],
2220
['Brevo', sendBrevoMail],
2321
['Mailjet', sendMailjetMail],
2422
];
2523

2624
export async function sendMail(opts: MailOptions) {
2725
const funcLogger = mainLogger.sub('sendMail');
2826

29-
for (const [serviceName, sendFunc] of _sendMailFuncs) {
27+
const randomizedSendMailFuncs = _sendMailFuncs
28+
.slice()
29+
.sort(() => Math.random() - 0.5);
30+
31+
for (const [serviceName, sendFunc] of randomizedSendMailFuncs) {
3032
try {
3133
await sendFunc(opts);
3234

0 commit comments

Comments
 (0)