I use mu4e for email. An attachment is simply text:

<#part filename="/absolute/path/to/file" disposition=attachment>

Can mu4e resize the attachment upon sending, e.g. converting a 3 MB JPEG image to a much smaller size?

1 Answer 1


One way of doing this is to find the attached filename and send it to the convert command. You would then have to specify the output filename and add it in place of the original attachment.

I would probably use mu4e-resize-image-attachments interactively, assuming it works, but you could also add it to the message-send-hook to do the conversion automatically before sending the message, which I think is what your question suggests.

Edit: For macOS, mmorin suggests using "sips --resampleWidth 600 %s --out %s" as an alternative to ImageMagick.

Edit: mmorin suggested a variable mu4e-inhibit-resize that you can toggle with M-x mu4e-inhibit-resize RET if you want to disable the resizing for a single message, based on this thread.

(defvar mu4e-resize-image-types '("jpg" "png" "svg" "jpeg")
  "List of attached image types to resize.")

(defvar mu4e-inhibit-resize nil)

(defun mu4e-resize-image-attachments ()
  (unless mu4e-inhibit-resize
    (let (cmds
       (mapconcat #'identity mu4e-resize-image-types "\\|")))
    (while (re-search-forward 
        (format "<#part.+\\(filename=\"\\)\\(.+\\(\\.%s\\)\\)\""
        nil t)
      (let* ((infile (match-string-no-properties 2))
         (outfile (concat (temporary-file-directory)
                  (file-name-nondirectory infile))))
        (push (format "convert %s -resize 600 %s"
              (shell-quote-argument infile)
              (shell-quote-argument outfile))
        (replace-match outfile t t nil 2)))
    (mapcar #'shell-command cmds)))))

(add-hook 'message-send-hook 'mu4e-resize-image-attachments)

(defun mu4e-inhibit-resize()
  (set (make-local-variable 'mu4e-inhibit-resize) t))

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.