-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/quick-actions
- Loading branch information
Showing
3 changed files
with
62 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,8 +38,8 @@ export const sendEmail = async ({ | |
try { | ||
// send mail with defined transport object | ||
await transporter.sendMail({ | ||
from: from || SMTP_FROM || `"Shelf" <no-reply@emails.shelf.nu>`, // sender address | ||
...(replyTo && { replyTo }), // reply to | ||
from: from || SMTP_FROM || `"Shelf" <updates@emails.shelf.nu>`, // sender address | ||
replyTo: replyTo || "[email protected]", // reply to | ||
to, // list of receivers | ||
subject, // Subject line | ||
text, // plain text body | ||
|
@@ -80,3 +80,37 @@ export const sendEmail = async ({ | |
// Preview only available when sending through an Ethereal account | ||
// console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info)); | ||
}; | ||
|
||
/** Utility function to add delay between operations */ | ||
async function delay(ms: number): Promise<void> { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
/** Process emails in batches with rate limiting | ||
* @param emails - Array of email configurations to send | ||
* @param batchSize - Number of emails to process per batch (default: 2) | ||
* @param delayMs - Milliseconds to wait between batches (default: 1000ms) | ||
*/ | ||
export async function sendEmailsWithRateLimit( | ||
emails: Array<{ | ||
to: string; | ||
subject: string; | ||
text: string; | ||
html: string; | ||
}>, | ||
batchSize = 2, | ||
delayMs = 1100 | ||
): Promise<void> { | ||
for (let i = 0; i < emails.length; i += batchSize) { | ||
// Process emails in batches of specified size | ||
const batch = emails.slice(i, i + batchSize); | ||
|
||
// Send emails in current batch concurrently | ||
await Promise.all(batch.map((email) => sendEmail(email))); | ||
|
||
// If there are more emails to process, add delay before next batch | ||
if (i + batchSize < emails.length) { | ||
await delay(delayMs); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters