Skip to content

feat(tools): add batch email sending utility#334

Merged
yash-pouranik merged 4 commits into
geturbackend:mainfrom
Nitin-kumar-yadav1307:feat/email-batch-script
Jun 22, 2026
Merged

feat(tools): add batch email sending utility#334
yash-pouranik merged 4 commits into
geturbackend:mainfrom
Nitin-kumar-yadav1307:feat/email-batch-script

Conversation

@Nitin-kumar-yadav1307

@Nitin-kumar-yadav1307 Nitin-kumar-yadav1307 commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a utility script under tools/ for sending outreach emails in configurable batches using Resend.

This script is intended for manual user acquisition campaigns, allowing maintainers to send a limited number of emails at a time (e.g. 100 emails per run) to avoid provider limits and gradually onboard new users.

Changes

  • Added tools/send-student-emails.js
  • Added tools/emails.txt as the email source file
  • Reads email addresses from a plain text file (one email per line)
  • Supports configurable batch sizes through CLI arguments
  • Logs successful and failed email deliveries
  • Reuses the existing Resend-based email infrastructure

Usage

Populate tools/emails.txt:

user1@example.com
user2@example.com
user3@example.com

Run the script:

node tools/send-student-emails.js 100

Examples:

node tools/send-student-emails.js 25
node tools/send-student-emails.js 50
node tools/send-student-emails.js 100

Example Workflow

  1. Export or copy email addresses into tools/emails.txt
  2. Run the script with the desired batch size
  3. Verify successful delivery in the logs
  4. Remove processed emails or update the list before the next run

Notes

  • tools/emails.txt contains placeholder/example entries only.
  • Replace the contents with the actual email list before running the script.
  • Email delivery requires a valid Resend API key in the environment.
  • The script is intended for manual outreach campaigns and batch sending.
  • No real email addresses are included in the repository.

Testing

Tested locally:

  • Script execution
  • Environment variable loading
  • Email file parsing
  • Batch size argument handling
  • Error handling for missing configuration

Actual email delivery testing requires a valid Resend API key and sender configuration.

Summary by CodeRabbit

  • Chores
    • Added email distribution infrastructure for operational use.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Nitin-kumar-yadav1307, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 35 minutes and 35 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a1e8bd18-3434-4c15-bb0d-2d2d0b97a512

📥 Commits

Reviewing files that changed from the base of the PR and between c7e409b and a94e10a.

📒 Files selected for processing (2)
  • tools/emails.txt
  • tools/promotional-emails.js
📝 Walkthrough

Walkthrough

A new Node.js script (tools/send-student-emails.js) is added to send onboarding emails via the Resend API. It reads recipients from a local text file, supports a CLI batch size argument, sends sequentially with a 1-second delay, and logs per-email outcomes. One seed email address is added to tools/db-queries/emails.txt.

Changes

Student Onboarding Email Sender

Layer / File(s) Summary
Script setup, Resend client, and sendEmail function
tools/send-student-emails.js, tools/db-queries/emails.txt
Imports fs/path, initializes dotenv, constructs a Resend client from RESEND_API_KEY_2 (fallback RESEND_API_KEY), and defines sendEmail() with a fixed sender, subject, and static HTML body. Seeds one recipient address (senkuishigami@gmail.com) in emails.txt.
main() batch orchestration and entry point
tools/send-student-emails.js
main() reads and cleans recipient emails from emails.txt, slices to the batch size from process.argv[2] (default 100), iterates sequentially calling sendEmail() with a 1-second delay, logs / per address, and prints Finished. main() is invoked at the bottom of the script.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hippity-hop, the emails fly,
One address seeded, batch queued up high.
The Resend API answers the call,
A tick or a cross logged out for each all.
One second of rest between every send —
The rabbit's onboarding has come to an end! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a batch email sending utility script to the tools directory.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tools/db-queries/emails.txt`:
- Line 1: The file tools/db-queries/emails.txt contains a real personal email
address (senkuishigami@gmail.com) on line 1, which is PII and violates the
placeholder-only workflow. Replace this real email address with a non-routable
placeholder email address such as student1@example.com or similar format that
follows the project's data seeding conventions.

In `@tools/send-student-emails.js`:
- Line 53: The console.log statements logging the email variable on lines 53 and
60 expose full email addresses as PII in the console output. Modify both
console.log calls to mask or hash the local part of the email address before
logging instead of logging the full email directly. Extract the local part
before the @ symbol and replace it with asterisks or a hash, keeping the domain
portion intact for reference (e.g., "****`@example.com`" format).
- Around line 6-9: The Resend client is being initialized without validating
that an API key is available, which defers the failure to send-time and makes
troubleshooting harder. Add an explicit guard check before the Resend client
initialization that verifies at least one of the API key environment variables
(RESEND_API_KEY_2 or RESEND_API_KEY) is set. If neither is present, throw an
error or exit the process immediately with a clear error message indicating the
missing API key configuration, then only proceed to create the Resend instance
if the validation passes.
- Line 39: The file path in the path.join call on line 39 is looking for
emails.txt directly in the tools directory, but this PR has moved the emails.txt
file to the db-queries subdirectory. Update the path.join call to include the
db-queries directory in the path hierarchy so it correctly resolves to
tools/db-queries/emails.txt instead of tools/emails.txt, which will prevent the
ENOENT file not found error.
- Around line 46-47: The batchSize variable on line 46 lacks validation and
accepts negative values, which when passed to the slice method on line 47 causes
unintended behavior by slicing from the start to a negative index, potentially
sending almost all emails. Add validation after parsing the batchSize from
process.argv[2] to ensure it is a positive integer greater than 0, and either
throw an error with a clear message or use a default value if the validation
fails.
- Line 15: The fallback sender email in the from field is hardcoded to
onboarding@resend.dev, which doesn't match the established email contract used
elsewhere in the project's email service logic. Replace this fallback value with
the same fallback sender pattern that is already used by existing email service
logic in the project to ensure consistency and avoid unverified sender policy
failures.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 65453ee8-baf0-4b21-a3fe-cd0b14543590

📥 Commits

Reviewing files that changed from the base of the PR and between b407d55 and c7e409b.

📒 Files selected for processing (2)
  • tools/db-queries/emails.txt
  • tools/send-student-emails.js

Comment thread tools/emails.txt Outdated
Comment thread tools/promotional-emails.js
Comment thread tools/send-student-emails.js Outdated
Comment thread tools/promotional-emails.js
Comment thread tools/send-student-emails.js Outdated
Comment thread tools/send-student-emails.js Outdated
@yash-pouranik yash-pouranik merged commit 8db0561 into geturbackend:main Jun 22, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants