I'm using contexts within mu4e, and I know how to add custom headers via the mu4e-header-info-custom list.

What I'd like to do, however, is to alter existing headers when replying or composing within certain contexts.

Here's one example: if I reply to a message that matches one of these special contexts, I'd like the To: header to be automatically changed to a different address, or to add additional addresses to the To: line.

Suppose the sender is [email protected]. If I reply to the message, I'd like the To: line to automatically be changed to:

To: [email protected]

... or even perhaps to ...

To: [email protected], [email protected], [email protected]

I might want to automatically change other existing headers, as well, such as Subject:.

Is there any way to do this in mu4e?


1 Answer 1


I will not take credit for this answer. cpbotha wrote a very informative blog post on this very topic. There are a few functions that need to be copied into your init.el or .emacs file, one for checking the recipient of the email, then executing a function that updates the user-full-name, user-mail-address, and updates the signature. This is a gist for you, but refer to the original blog for more useful configuration ideas.

(defun get-string-from-file (filePath)
  "Return FILEPATH's file content."
    (insert-file-contents filePath)

(defun my-mu4e-personal()
  (message "personal mail account")
  (setq user-full-name "MyFirst MyLast"
    user-mail-address "[email protected]"
    mu4e-compose-signature (get-string-from-file "~/.signature")))

(defun my-mu4e-work()
  (message "work mail account")
  (setq user-full-name "MyFirst MyLast"
    user-mail-address "[email protected]"
    mu4e-compose-signature (get-string-from-file "~/.signature-work")))

;; when you reply to a message, use the identity that the mail was sent to
;; the cpbotha variation -- function that checks to, cc and bcc fields
(defun cpb-mu4e-is-message-to (msg rx)
  "Check if to, cc or bcc field in MSG has any address in RX."
  (or (mu4e-message-contact-field-matches msg :to rx)
      (mu4e-message-contact-field-matches msg :cc rx)
      (mu4e-message-contact-field-matches msg :bcc rx)))

;; we only do something if we recognize something (i.e. no stupid default)
(add-hook 'mu4e-compose-pre-hook
  (defun my-set-from-address ()
    "Set current identity based on to, cc, bcc of original."
      (let ((msg mu4e-compose-parent-message)) ;; msg is shorter...
        (if msg
           ((cpb-mu4e-is-message-to msg "[email protected]")
           ((cpb-mu4e-is-message-to msg "[email protected]")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.