Follow up on emails with mu4e and org capture
When I send an email, I often want my agenda to remind me to follow up
a few days later.  Thanks to Dirk-Jan C. Binnema's help, I was able to
set this up with mu4e and org-capture.
mu4e + org-capture
Here's the code:
(add-to-list 'org-capture-templates ("efu" "Follow Up" entry (file+olp "todo/todo.org" "Email" "Follow Up") "* TODO Follow up with %(eval sent-message-to) on [[mu4e:msgid:%(eval sent-message-id)][%(eval sent-subject)]] SCHEDULED: %(org-insert-time-stamp (org-read-date nil t \"+3d\")) %i")) (add-hook 'message-sent-hook #'my/org-capture-sent-mail) (defun my/org-capture-sent-mail () "Prepare to capture sent mail after window configuration is reset." (let* ((sent-message-id (replace-regexp-in-string "[<>]" "" (message-fetch-field "Message-Id"))) (sent-message-to (replace-regexp-in-string " <.*>" "" (message-fetch-field "To"))) (sent-subject (or (message-fetch-field "Subject") "No subject"))) (org-capture nil "efu") (add-hook 'mu4e-compose-post-hook #'my/pop-to-buffer-org-capture-mail 99))) (defun my/pop-to-buffer-org-capture-mail () (pop-to-buffer (car (match-buffers (lambda (buffer) (equal "efu" (plist-get (buffer-local-value 'org-capture-current-plist buffer) :key)))))) (remove-hook 'mu4e-compose-post-hook #'my/pop-to-buffer-org-capture-mail))
After I send an email, I see the org-capture pop-up window
pre-filled from the template:
*** TODO Follow up with John Doe on [[mu4e:msgid:1234576890][Beautiful Snowy Morning]] SCHEDULED: <2025-02-06 Wed>
If I run org-capture-finalize (C-c C-c), then I'll be reminded in
three days to follow up on the email.  Before capturing the reminder,
I can add more information or edit the date if I want to have more or
less time before it shows up on my agenda.  Alternatively, I can run
org-capture-kill (C-c C-k) if I don't want to be reminded at all.
Technical Details
After closing a composition buffer, mu4e restores your window
configuration in mu4e-compose-post-hook, a feature which I want to
keep.  However, this means that the org-capture buffer gets hidden
when the windows are restored.1 The solution above is to add a
self-removing hook function my/pop-to-buffer-org-capture-mail to
mu4e-compose-post-hook which pops back to the org-capture buffer
after the window configuration is restored.
Links
- Issue in mu4e tracker with djcb's comments
- My Emacs configuration (search for my/org-capture-sent-mail)
Footnotes:
I want to interact with the org capture buffer each time I send
an email, so I can edit or cancel the reminder while capturing it.  If
I didn't want to interact with the org capture buffer, I could put
:immediate-finish in the org-capture template and get rid of
my/pop-to-buffer-org-capture-mail.