Developer tools · Swift

Mailpit in the macOS menu bar

A small Swift app for noticing development email, with a few lessons about reconnecting, notifications and shipping a macOS utility.

Testing an email flow usually means doing something in the application, switching to Mailpit, and checking whether the message arrived. For a password reset or a signup email, the useful signal is small: a message came in, and here is a shortcut to it.

I built Mailpit Menubar to put that signal in the macOS menu bar. It shows the unread count, lists recent messages, and posts a native notification when a new message arrives. Clicking a notification or a menu item opens that message in Mailpit’s web UI.

The app is a companion to an existing Mailpit server. It does not run the server or replace its message viewer. That keeps the interface small: an envelope, a count, and a menu.

A menu is enough interface

The UI is built with AppKit: an NSStatusItem owns the menu bar button, and an NSMenu holds the recent messages and actions. Unread messages appear in bold with a dot; senders use smaller, secondary text. The list is capped at twelve messages, with subjects truncated to sixty characters so one long email subject cannot take over the menu.

There are shortcuts to open Mailpit, refresh the connection and mark everything as read. A URL dialog points the app at another server or port. It also supports a webroot such as http://localhost:8025/mailpit, preserving that prefix when building API and message URLs.

The envelope changes when the connection drops. That distinction matters: an empty inbox and an unreachable server should not look like the same state.

Mailpit web inbox at localhost:8025 showing the same four sample messages.
The same four messages in Mailpit’s web UI. The menu bar app provides a shortcut to this existing inbox and its message viewer.

Events for speed, a snapshot for recovery

The client opens a WebSocket to /api/events. A new event supplies the message for the menu and notification; stats events update the total and unread counts. Delete, truncate and update events trigger a refresh of the recent list.

Alongside that stream, the client fetches /api/v1/messages?limit=12. The snapshot populates the menu at startup and brings it back into sync after reconnecting. The first snapshot establishes a baseline without announcing every existing email as new.

After that first sync, the app compares returned message IDs with the IDs it has already seen. An unseen message in a later snapshot can produce a notification even if the socket missed its arrival. If more than three unseen messages turn up in that snapshot, the app sends one summary notification.

There is a deliberate limit here: recovery only examines the twelve messages returned by the recent-list request. It is useful catch-up for a development inbox, not a durable delivery guarantee. A large burst during a long disconnection can exceed that window, and restarting the app establishes a new baseline.

The reconnect delay starts at one second, doubles after failures and caps at thirty seconds. A twenty-second ping checks the socket. Each connection also gets a generation number, so callbacks from an older socket can be ignored after a replacement has started. That last detail is easy to miss: cancelling asynchronous work does not mean every callback associated with it has vanished.

Notifications need the app bundle

The notification content comes from the sender, subject and message snippet. The message ID travels in userInfo, so clicking the notification can open /view/<id> rather than dropping the user at the inbox. A summary notification opens the inbox instead.

Native macOS notification from Mokotahi Reports with the subject Your weekly report is ready and a sample message preview.
A native notification for the sample weekly report, with sender, subject and preview. The menu bar badge has updated to four unread messages.

The practical development detail is packaging. This project’s notification flow needs a real .app bundle; running the executable through swift run alone is not the supported way to test it. The Makefile builds the release binary, adds the icon and Info.plist, embeds Sparkle, signs the bundle and launches it.

make run

On first launch, macOS asks for notification permission. If that prompt was dismissed, notifications can be enabled in System Settings. For a menu bar utility, it is worth testing the complete path: new message, visible notification, click, correct message in the browser.

Shipping is a separate piece of work

The application code is small, but distributing a macOS app adds its own machinery. Launch at Login uses SMAppService; installing the bundle in /Applications gives it a stable home.

Updates use Sparkle. The app reads an appcast from the latest GitHub release and verifies update signatures against the public key embedded in its configuration. The release script builds with a Developer ID identity and the hardened runtime, notarizes and staples the app, creates and notarizes a DMG, generates the appcast, then uploads the release assets.

Sparkle brings nested helpers inside its framework. The Makefile signs those from the inside out before signing the framework and application bundle. Local builds use ad-hoc signing by default; they are useful for development, but do not have the matching signature needed for Sparkle to install the published updates over them.

Try it

The project targets macOS 14 or later and builds with Swift 6 and Xcode 16 or newer command-line tools. With Mailpit already running, the default connection is http://localhost:8025.

git clone https://github.com/tuttinator/mailpit-menubar.git
cd mailpit-menubar
make run

Use make install to copy the bundle into /Applications. The repository README covers the menu actions and release prerequisites.

This is the sort of utility I like: a small addition to an existing workflow. Mailpit still does the work of inspecting email. The menu bar app makes it easier to notice when there is something to inspect.