DEV Community

Shawon Hossain (1809256)
Shawon Hossain (1809256)

Posted on

Why We Built an Offline-First Architecture for Temporary Emails on Android

Why We Built an Offline-First Architecture for Temporary Emails on Android

Handling temporary inboxes on mobile is deceptively complex. Most web-based disposable email tools keep data strictly in the browser session. If the user refreshes, switches tabs, or navigates away, the inbox—and that crucial 6-digit verification code—vanishes.

When designing Mailfo, an Android disposable email client, our goal was to eliminate this friction entirely.


The Challenge: Ephemeral Yet Durable

The core paradox of a disposable email app:

  • The email address is ephemeral (discarded after use).
  • The incoming verification email is mission-critical (a user waiting for an OTP cannot afford to lose it due to a background process kill).

On Android, background webviews and tabs get aggressively reaped under memory pressure. If a user opens Chrome to submit a form, switches to their email app, and finds the inbox resetting, the signup flow is ruined.


Architectural Decision: Room Database as the Single Source of Truth

Rather than holding message payloads in runtime memory (ViewModel or state holder), we route every inbound email through a local Room SQLite database:

@Entity(tableName = "cached_messages")
data class CachedMessage(
    @PrimaryKey val id: String,
    val sender: String,
    val subject: String,
    val snippet: String,
    val bodyHtml: String?,
    val receivedAt: Long,
    val isRead: Boolean = false
)
Enter fullscreen mode Exit fullscreen mode

By persisting incoming payloads locally before rendering them in Jetpack Compose:

  1. Zero State Loss: Switching between apps or triggering process death never deletes received verification emails.
  2. Instant Search & History: Users can quickly reference previous signups without re-fetching from the network.
  3. Optimistic UI: The inbox renders instantly on cold start.

Real-Time Push vs Polling: Finding the Sweet Spot

High-frequency polling kills battery life and triggers rate limits on backend workers. To solve this, we implemented an adaptive backoff polling mechanism:

  • Foreground Focus: 5-second interval while the user is actively waiting on the inbox screen.
  • Smart Dormancy: If no new messages arrive within 3 minutes, polling throttles to 30-second heartbeats.
  • Regex OTP Parsing: Inbound emails are scanned locally on the device with regular expressions to surface 4-8 digit OTP codes as high-contrast chips with single-tap copy.

Telegram Bot & Ecosystem Expansion

To make temporary inboxes universally accessible across mobile workflows without app installs, we also launched the official @mailfo_official_bot on Telegram, connecting to the same Cloudflare Workers backend engine.

For developers and power users needing native performance, background notifications, and offline caching, the native Mailfo Android App is available on Google Play Store.

How do you handle ephemeral yet critical data synchronization in your mobile apps? Let's discuss in the comments below!

Top comments (0)