Bulk Messaging System

An Electron Desktop app for marketing campaign & broadcast management, using either whatsapp, gmail or a SMTP server

Bulk sending engine

Introduction#

Bulk send loop for WhatsApp (and the email cousins): iterate contacts, personalize, delay, report progress, keep going on single failures.

Project structure#

The application is organized as a cross-platform desktop app :

  • Electron main process orchestrating IPC handlers and integrations
  • React frontend for user controls and progress display
  • Python backend utilities for contact processing and validation
  • Local development server and prototype utilities

Core components#

  • Electron main process manages WhatsApp client lifecycle, handles IPC events, and coordinates email sending via Gmail API and SMTP.
  • React components provide user controls for connecting to WhatsApp, importing contacts, composing messages, and monitoring progress.
  • Python backend exposes REST endpoints for contact import and parsing, and standalone utilities for contact extraction and phone number validation.
  • Pyodide runtime enables running Python logic directly in the renderer process for manual number parsing.

Key responsibilities:

  • Contact ingestion and normalization
  • Message personalization
  • Rate limiting and throttling
  • Delivery confirmation and status tracking
  • Error handling and retries

Architecture overview#

The bulk sending engine integrates three channels:

  • WhatsApp Web: QR-based authentication, per-contact registration checks, and per-message delays.
  • Gmail API: OAuth2-based sending with per-email delays and progress updates.
  • SMTP: Transport-based sending with per-email delays and progress updates.

Detailed component analysis#

WhatsApp bulk sending#

Workflow:

  • Initialize WhatsApp client with local authentication strategy.
  • Display QR code for user authentication.
  • After authentication, iterate over contacts:
  • Construct chat ID from phone number.
  • Check if the number is registered on WhatsApp.
  • Personalize message using {{name}} placeholder.
  • Send message with a fixed delay between attempts.
  • Report completion metrics (sent vs failed).

Key implementation details:

  • Personalization: Replace {{name}} with contact name or default value.
  • Registration check: Uses isRegisteredUser(chatId) to avoid sending to unregistered numbers.
  • Delays: Fixed delays between attempts to reduce rate limits and detection risk.
  • Status reporting: Real-time updates via IPC channels for UI rendering.

Email bulk sending (gmail API)#

Workflow:

  • Authenticate via OAuth2 and persist tokens.
  • For each recipient:
  • Prepare email payload.
  • Send via Gmail API.
  • Emit progress updates.
  • Apply configurable delay between sends.

Key implementation details:

  • OAuth2 flow: Generates auth URL, captures authorization code, exchanges for tokens.
  • Token persistence: Stores tokens securely for reuse.
  • Progress tracking: Emits structured progress events with current/total and per-recipient status.
  • Delay-based rate limiting: Applies delay between sends to avoid throttling.

Email bulk sending (SMTP)#

Workflow:

  • Validate SMTP configuration.
  • Create transport and verify connectivity.
  • For each recipient:
  • Build email options (HTML and plain text).
  • Send via SMTP.
  • Emit progress updates.
  • Apply configurable delay between sends.

Key implementation details:

  • Transport verification: Checks SMTP readiness before sending.
  • Credential handling: Optional saving of non-secret config (host/port/secure/user).
  • Progress tracking: Same event-driven pattern as Gmail API.
  • Delay-based rate limiting: Consistent throttling across providers.

Contact processing and validation#

The system supports importing contacts from CSV, TXT, and Excel files, and validating/normalizing phone numbers.

Key implementation details:

  • CSV/Excel parsing: Heuristically detects phone and name columns.
  • TXT parsing: Splits by separators and extracts likely phone numbers.
  • Manual parsing: Uses Pyodide to run Python logic in the renderer for quick number extraction.
  • Validation: Enforces digit-only length constraints and optional leading plus sign normalization.

Rate limiting and spam prevention#

  • WhatsApp:
  • Fixed delays between sending attempts to registered users and between failures.
  • Registration checks prevent sending to unregistered numbers, reducing bounce-related errors.
  • Gmail/SMTP:
  • Configurable delay between emails to avoid throttling and rate limits.
  • Progress events allow users to adjust delay dynamically.

Habits that help:

  • Start with conservative delays and increase gradually based on provider feedback.
  • Monitor delivery failures and reduce batch sizes for problematic domains/providers.
  • Respect provider-specific rate limits and quotas.

Delivery confirmation and status tracking#

  • WhatsApp:
  • Real-time status updates for QR generation, authentication, and per-contact send results.
  • Completion summary with sent and failed counts.
  • Gmail/SMTP:
  • Per-email progress events with current/total counters and per-recipient status.
  • Structured failure details for diagnostics.

Retry mechanisms and error recovery#

  • WhatsApp:
  • Attempts to send to registered users only; failures are recorded and retried on subsequent runs.
  • Disconnection handler resets client state and clears cached files.
  • Gmail/SMTP:
  • Per-email failure events include error messages; UI can trigger reattempts selectively.
  • Transport verification helps detect misconfiguration early.

Recommendations:

  • Implement explicit retry loops for transient failures.
  • Persist partial results to resume interrupted campaigns.
  • Provide user controls to pause/resume and adjust retry policies.

Dependency analysis#

External libraries and services:

  • Electron: Desktop runtime and IPC
  • whatsapp-web.js: WhatsApp Web integration
  • googleapis: Gmail API authentication and sending
  • nodemailer: SMTP transport
  • qrcode: QR code generation for WhatsApp
  • Pyodide: Python runtime in the browser for manual number parsing

Performance considerations#

  • Concurrency control: Limit simultaneous send operations to respect provider rate limits.
  • Batch sizing: Reduce batch size for providers with strict quotas.
  • Memory management: Clear cached files and reset client state on disconnects.
  • Network resilience: Use exponential backoff for retries and circuit breaker patterns.
  • UI responsiveness: Offload heavy tasks to background threads and emit frequent progress updates.

Troubleshooting guide#

Common issues and resolutions:

  • WhatsApp QR code not loading:
  • Ensure network connectivity and restart the app.
  • Clear cached files and retry initialization.
  • Gmail authentication failures:
  • Verify OAuth2 client credentials and ensure Gmail API is enabled.
  • SMTP connection issues:
  • Confirm server settings, ports, and TLS configuration.
  • Contact import errors:
  • Validate file format and encoding; ensure proper column headers.

Conclusion#

Respect the delay. WhatsApp bans are worse than a slow progress bar.