cd ../case-studies
~/case-studies/email-automator.md
Architectural Deep-Dive

Email Automator

A Gmail-based bulk email system built around safe execution, preview-first confidence, and messy real-world data.

Email Automator screenshot

title: "Email Automator: Deterministic Bulk Dispatch System" excerpt: "How a Gmail-based automation tool eliminated high-stakes batch errors and merged messy CSV data safely." date: "Aug 2025 - Present" stage: "production" readTime: "6 min read" stack: ["Next.js", "NextAuth", "Google OAuth", "Gmail API", "Handlebars"] liveUrl: "https://emailauto.syedsystems.dev"

1. What problem does this product solve?

Email Automator was built because real-world bulk communication operations are chaotic in a way traditional marketing tools ignore. The users I had in mind were not marketers running polished newsletters; they were teachers, university operators, small teams, and admins sitting with two ugly CSV files, a strict deadline, a Gmail account, and a very real fear of sending confidential student reports or marks to the wrong person.

Standard bulk email tools require importing lists into third-party servers, which breaks privacy rules and forces users to trust external mail providers with sensitive data. Furthermore, messy CSV data (with inconsistent column names like email_address, E-Mail, or missing fields) often leads to embarrassing batch failures mid-send.

Email Automator solves this by creating a preview-first, deterministic execution pipeline: connect Google once, upload structured CSV data, auto-normalize records, template the message, visually inspect every row, and dispatch through the user's own Gmail API identity.


2. Impact on Society (How people benefit)

  • Eliminates High-Stakes Embarrassment: By implementing pre-send row-by-row previews and field normalization, administrators avoid sending wrong grade sheets or confidential documents to unintended recipients.
  • Privacy First: Eliminates the need to export sensitive student or customer lists to third-party marketing databases. Data stays within the user's own Google workspace.
  • Zero Cost & Low Friction: Empowers educational operators and small organizations to execute personalized dispatches without purchasing expensive Enterprise email software.

3. User Count

Used by multiple academic departments and organizational teams to process hundreds of personalized announcements, exam result dispatches, and administrative notices monthly.


4. Tech Stack

  • Framework: Next.js 14 (App Router)
  • Authentication: NextAuth.js with Google OAuth 2.0
  • API & Delivery: Official Google Gmail API (v1)
  • Templating Engine: Handlebars.js
  • Data Normalization: PapaParse & custom schema inference logic

5. Justification of Tech Stack

The Bottleneck of Legacy Approaches:

Traditional SaaS platforms like Mailchimp or SendGrid require double-opt-in workflows, external domain verification (SPF/DKIM/DMARC configuration), and uploading recipient data to external servers. For a university professor or department admin, setting up custom DNS for a one-off notification is impossible. Conversely, standard mail-merge add-ons for Google Sheets are prone to silent failures, hitting Gmail rate limits without feedback, and corrupting variable placeholders.

Why this stack:

  • Gmail API & Google OAuth: Direct OAuth integration allows sending emails directly from the user's own @gmail.com or Google Workspace identity (@iut-dhaka.edu). Receipients see an authentic, personal email from their professor, dramatically boosting open and trust rates while bypassing third-party DNS setup.
  • Next.js & Handlebars.js: Enables instant, 60fps client-side rendering of merged data tables. Handlebars provides strict, predictable variable evaluation ({{name}}, {{grade}}) so missing keys trigger explicit UI warnings rather than rendering blank spaces in live emails.
  • NextAuth.js Token Refresh Management: Automates background refresh token rotation for Google OAuth, ensuring long-running bulk batches don't fail halfway through due to expired access tokens.