Bulk Messaging System

Documentation

SMTP authentication

Introduction#

This page explains SMTP authentication methods and credential management in the application. It covers username/password authentication, encrypted credential storage, OAuth2 Gmail authentication, and best practices for secure operation. It also documents common failure scenarios, troubleshooting steps, and step-by-step setup guides for popular email providers.

Project structure#

The application is an Electron + React desktop app with dedicated modules for authentication and email sending:

  • Electron main process handles IPC, Gmail OAuth2, and SMTP operations
  • Renderer components manage UI and user interactions
  • Credential storage uses encrypted local storage

Core components#

  • Gmail OAuth2 authentication flow with browser window and token persistence
  • SMTP username/password authentication with optional encrypted credential saving
  • Encrypted credential storage using electron-store
  • IPC bridge exposing safe methods to renderer process
  • UI components for configuring and sending emails

Key implementation references:

  • Gmail OAuth2: handleGmailAuth, handleSendEmail
  • SMTP send: handleSMTPSend
  • Credential storage: Store initialization, getSavedSMTPConfig
  • IPC exposure: preload.js
  • UI orchestration: BulkMailer.jsx

Architecture overview#

The renderer invokes main-process methods via IPC. The main process performs authentication and sends emails, persisting credentials securely when requested.

Detailed component analysis#

SMTP username/password authentication#

SMTP authentication uses nodemailer with explicit credentials. The handler validates configuration, optionally persists non-sensitive SMTP metadata, creates a transporter, verifies connectivity, and sends emails with progress updates.

Key behaviors:

  • Validates presence of host, port, user, and pass
  • Optional saving of non-sensitive SMTP metadata (without password)
  • TLS verification with self-signed certificate allowance
  • Per-recipient progress reporting via IPC
  • Delay between emails for rate limiting

Security considerations:

  • Password is not persisted; only non-sensitive metadata may be saved
  • TLS verification occurs before sending
  • Self-signed certificate verification can be disabled for testing environments

Gmail OAuth2 authentication#

The application uses Google OAuth2 with a browser window for consent and token exchange. Tokens are stored securely and reused for sending emails.

Token lifecycle:

  • Token retrieval checks for stored credentials
  • Token is attached to Gmail API client for sending
  • Self-signed certificate verification disabled for API transport

Credential storage and security#

  • SMTP metadata (host, port, secure flag, user) can be saved when requested; passwords are intentionally omitted
  • Gmail tokens are stored securely in encrypted local storage
  • Electron’s contextBridge exposes only safe IPC methods to renderer

Security controls:

  • electron-store encrypts stored data at rest
  • Renderer cannot access Node.js APIs directly due to context isolation
  • Only whitelisted IPC methods are exposed

UI integration and workflows#

  • BulkMailer orchestrates form rendering and validation
  • SMTPForm collects host/port/user/pass and triggers send
  • GmailForm manages OAuth flow and sends emails via API
  • Both emit progress events to the activity log

Dependency analysis#

External libraries and their roles:

  • nodemailer: SMTP transport and sending
  • googleapis: Gmail API client and OAuth2 flow
  • electron-store: encrypted local storage for credentials
  • whatsapp-web.js: WhatsApp integration (unrelated to SMTP but part of the app)

Performance considerations#

  • Rate limiting: configurable delay between emails to avoid throttling and detection
  • Connection verification: SMTP verify reduces failures mid-batch
  • Batch progress: real-time updates minimize perceived latency
  • Token reuse: OAuth2 tokens avoid repeated consent prompts

[No sources needed since this section provides general guidance]

Troubleshooting guide#

Common SMTP errors and resolutions:

  • Invalid credentials
    • Verify username/email and password
    • Ensure secure flag matches server requirements (SSL/TLS)
    • Confirm firewall and network access to SMTP host/port
  • Account disabled or locked
    • Reset password or unlock account via provider portal
    • Use app-specific passwords for providers requiring it
  • Two-factor authentication requirements
    • Use app-specific passwords for Gmail
    • Enable less secure apps or use OAuth2 where supported
  • Provider-specific issues
    • Gmail: Use App Passwords and correct host/port
    • Outlook: Use TLS on port 587

Common Gmail OAuth2 errors and resolutions:

  • Missing environment variables
    • Ensure GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET are set
  • Consent screen issues
    • Re-run OAuth flow; ensure prompt consent is configured
  • Token exchange failures
    • Check redirect URI and network connectivity
    • Clear stored token and re-authenticate

Credential storage issues:

  • Encrypted store not available
    • Ensure electron-store is installed and initialized
    • Check permissions for app data directory

Conclusion#

The application supports both SMTP username/password and Gmail OAuth2 authentication. SMTP credentials are not persisted, while Gmail tokens are stored securely. The UI provides guided workflows, progress tracking, and reliable error handling. Follow the provider-specific setup guides and best practices to maintain secure, reliable email delivery.

[No sources needed since this section summarizes without analyzing specific files]

Appendices#

Step-by-Step: gmail SMTP (app password)#

  • Obtain App Password from Google account settings
  • Use host: smtp.gmail.com, port: 587 (TLS), secure: false
  • Enter username and App Password in SMTP form
  • Optionally save non-sensitive SMTP metadata

Step-by-Step: outlook SMTP#

  • Host: smtp-mail.outlook.com, Port: 587, Secure: false (TLS)
  • Enter username and password in SMTP form
  • Optionally save non-sensitive SMTP metadata

Best practices for credential security#

  • Prefer OAuth2 where available (Gmail)
  • Use app-specific passwords for SMTP providers
  • Limit saved metadata; never persist passwords
  • Regularly rotate credentials and monitor usage
  • Enforce rate limits and validate inputs
  • Keep dependencies updated and review security advisories