Have emacs+mu4e handle mailto: links

30 views
Skip to first unread message

jman

unread,
Jun 28, 2025, 5:46:27 AMJun 28
to mu-di...@googlegroups.com

Hi,

I am trying to configure Emacs to react to "mailto:" links by configuring the appropriate XDG
mimetype, which by default (at least on Debian) is:

$ xdg-mime query default x-scheme-handler/mailto
emacs-mail.desktop

That .desktop file executes:
Exec=emacs -f message-mailto %u

which in my case is not sufficient to start emacs, then mu4e, then compose an email.

What I probably would like to happen is the equivalent of running:
$ emacs --eval '(mu4e) (mu4e-compose-new "%u")'

But that doesn't work either. I have found an old SO post[0] suggesting to set:

--8<---------------cut here---------------start------------->8---
(setq
mail-user-agent #'mu4e-user-agent
message-mail-user-agent t)
--8<---------------cut here---------------end--------------->8---

to have mu4e handle the `message-mailto` but, again, this doesn't seem to work for me. I see an
error in *Messages*
mu4e-error: [mu4e] Root maildir unknown; did you start mu4e?

I am a bit confused about what to do: has anyone suggestions to share?

I would like the following to happen:
- if Emacs is not running, start Emacs and open a mu4e compose buffer prepopulating email fields
(To, Cc, Subject, ...) based on the input
- if Emacs is running, open a new buffer mu4e compose buffer in the current instance

Thanks!

[0]: https://emacs.stackexchange.com/a/77624

Dirk-Jan C. Binnema

unread,
Jun 30, 2025, 11:06:48 PMJun 30
to mu-di...@googlegroups.com
It works if you ensure mu4e is running beforehand; easiest to do that is
to use emacsclient (with a server that has mu4e running, and
message-mail-user-agent set to t):

emacsclient -c -e '(message-mailto "mailto:f...@example.com?subject=test")'

If you want to start that emacs server opportunistically (i.e., not
beforehand), I suppose that should be doable with a little
shell-scripting.

Kind regards,
Dirk.

--
Dirk-Jan C. Binnema Helsinki, Finland
e:dj...@djcbsoftware.nl w:www.djcbsoftware.nl
gpg: 6987 9CED 1745 9375 0F14 DA98 11DD FEA9 DCC4 A036

jman

unread,
Jul 6, 2025, 2:29:22 PMJul 6
to Dirk-Jan C. Binnema, mu-di...@googlegroups.com
"Dirk-Jan C. Binnema" <dj...@djcbsoftware.nl> writes:

> It works if you ensure mu4e is running beforehand; easiest to do that is
> to use emacsclient (with a server that has mu4e running, and
> message-mail-user-agent set to t):
>
> emacsclient -c -e '(message-mailto "mailto:f...@example.com?subject=test")'
>
> If you want to start that emacs server opportunistically (i.e., not
> beforehand), I suppose that should be doable with a little
> shell-scripting.

Thank you Dirk, I think I got it working.

In addition, I would probably change the suggested command to:

emacsclient -c -n -e '(message-mailto "mailto:f...@example.com?subject=test")'

where `-n` (or `--no-wait`) makes the emacslient detach immediately after evaluating the
code. Otherwise the emacsclient will never return.

One more question: it seems that `mu4e-compose-mail` is wrapping the underlying `compose-mail` from
simple.el.

I am curious if it would be possible to add a little twist to improve the UX: can the email compose
buffer inherit the email subject? Example `*test*` in your example. Currently the buffer name is
always "No subject".

Thanks
Reply all
Reply to author
Forward
0 new messages