Nicolas Cavigneaux: emacs-mailto: Open macOS mailto: Links in Emacs

Wait 5 sec.

What it isemacs-mailto makes macOS mailto: links open in Emacs, using whatevermail-user-agent you already have configured — mu4e, notmuch, Gnus, Rmail,or plain message-mode. Click a mailto: link in your browser, and Emacscomes to the front with a compose buffer already addressed.The project lives atsr.ht/~bounga/emacs-mailto, whereyou’ll find the source and the ticket tracker.The problem it solvesThe GNU Emacs NS port — as shipped by emacs-plus, emacs-mac, or theofficial build — does not handle mailto: URLs.When Emacs is already running, clicking a mailto: link activates Emacs butthe URL never arrives: macOS brings the app to the front and drops the URLApple-event before it ever reaches Emacs Lisp. So nothing happens — nocompose buffer — and there is no way to fix it from your config, because theevent never gets there in the first place.That’s the whole frustration emacs-mailto exists to remove.How it worksemacs-mailto sidesteps the dropped Apple-event with a tiny relay appregistered as your default mail application. On a mailto: click, it bringsEmacs to the front and hands the URL to emacsclient:open -a Emacsemacsclient -n -e "(run-at-time 0 nil (lambda () (browse-url-mail \"\")))"browse-url-mail parses the mailto: URL — recipient, subject, body — andopens a compose buffer through your mail-user-agent. The run-at-timewrapper lets emacsclient return immediately instead of blocking on aninteractive prompt, such as a From-address picker.A few details make it painless in practice: emacsclient is located automatically at runtime (Homebrew on AppleSilicon or Intel, MacPorts, ~/.local/bin, or /usr/bin), so no path ishard-coded. The app is built and ad-hoc signed locally by the installer, so there isno Gatekeeper quarantine and no pre-built binary to trust.Requirements macOS Emacs running with a server (M-x server-start, or the Doom/Spacemacsdefaults), so emacsclient can reach it A configured mail-user-agent — this is what actually opens the composebufferInstallationClone the repository and run the installer:git clone https://git.sr.ht/~bounga/emacs-mailtocd emacs-mailto./install.shThis compiles Emacs Mailto.app into ~/Applications, registers it, andsets it as the default mailto: handler.Test it:open "mailto:test@example.com?subject=Hi"Emacs should come to the front with a compose buffer addressed totest@example.com.If your Emacs app has a different name, or you want a custom bundleidentifier, override them with environment variables:EMACS_APP="Emacs" BUNDLE_ID="org.nongnu.emacs-mailto" ./install.shA caveat about the default mail appThe relay runs as a background agent (LSUIElement), so it does notshow up in Mail → Settings → General → “Default email application”. Thatmenu may keep displaying another app — ignore it. To check the real handler,ask LaunchServices directly:swift -e 'import AppKit; print(NSWorkspace.shared.urlForApplication(toOpen: URL(string:"mailto:x@y.z")!)!.path)'It should print .../Emacs Mailto.app.Uninstall./uninstall.shThis removes the app and resets the mailto: handler to Apple Mail.Wrapping upThat’s the whole tool — a small relay that removes a long-standing papercutof running Emacs as a mail client on macOS. It’s MIT licensed. If you hit arough edge with your particular Emacs build or macOS version, the tracker ison the project page atsr.ht/~bounga/emacs-mailto.