Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do you make Emacs Message (C-x m) save outgoing mails?

Is there a standard way to do this?

You could C-x C-s but this is inefficient and easy to forget, besides, you can't be 100% it is the mail actually sent: you might have done some last minute changes that you later forgot about.

Could this (save-buffer) be invoked from a "send message" hook and be automated? (Like text-mode-hook.) If so, what hook? (How do you get the hooks of a mode?)

BCC to yourself: not very elegant?

FCC: seems to be best solution, still, must be automated, both invocation and a good file name generated.

share|improve this question

Just got this to work. Put in .emacs:

(defun save-sent-mail ()
  (write-file (format-time-string "~/Mail/sent/%Y-%m-%d_%T") nil) )
(add-hook 'message-send-hook 'save-sent-mail)
share|improve this answer
If Emacs fail send mail it would not call message-sent-hook. But message-send-hook it call before ever try do so.. – gavenkoa Jul 10 '12 at 12:47

You can set the variable gcc-self to T for any groups you want to archive.

See its documentation here. (or (gnus) Group Parameters)

EDIT: gcc-self isn't a « classic » variable, you've to set it via gnus-parameter.

(setq gnus-parameters
         (gcc-self . t))))
share|improve this answer
How do I set that variable? I don't get anything with Describe variable and gcc-self. – Emanuel Berg Jun 14 '12 at 16:47
@EmanuelBerg: edited – Daimrod Jun 15 '12 at 16:12
@Daimrod Look for my solution too... – gavenkoa Jul 8 '12 at 19:07

I use more complicate solution:

(defconst my-safe-filename-char-regex "[[:alnum:]-_!.@]"
  "Safe file names.")

(defun my-clean-filename (filename)
   (lambda (ch) (or (when (string-match my-safe-filename-char-regex (char-to-string ch)) (char-to-string ch)) "-"))
   filename "") )

(defun my-message-save ()
  "Store message in `gnus-article-save-directory' after
successful sending. It is possible that mail rejected and I lost
it completely, this func save it for me."
  (unless (eq major-mode 'message-mode)
    (error "Attempt to call my-message-save in non message-mode buffer"))
  (make-directory gnus-article-save-directory t)
  (let ( (buf (current-buffer))
         (field-to (my-clean-filename (or (message-fetch-field "Newsgroups") (message-fetch-field "To"))))
         (field-subject (my-clean-filename (message-fetch-field "Subject")))
         file )
    (setq file (concat gnus-article-save-directory "/" (format-time-string "%F_%T") "_" field-to "_" field-subject))
    (with-temp-file file
      (insert-buffer buf)
      )) )
(add-hook 'message-sent-hook 'my-message-save)

Also note that I use message-sent-hook instead of message-send-hook.

share|improve this answer
"Also note that I use message-sent-hook instead of message-send-hook." I guess that means you know the difference, so please tell me :-) – Emanuel Berg Jul 9 '12 at 18:57
If Emacs fail send mail it would not call message-sent-hook. But message-send-hook it call before ever try do so... – gavenkoa Jul 10 '12 at 12:46
Also I trapped in error with my example. Look for thread.gmane.org/gmane.emacs.help/85745 – gavenkoa Jul 10 '12 at 12:46
I update code, now it properly handle / char in message fields. – gavenkoa Jul 10 '12 at 15:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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