The following, added to your .emacs, will save all mail sent with mail-mode or message-mode. The name of the save file is set with the mail-sent-save-file variable. Messages are saved in Unix mailbox format; this makes the save folder usable by, for example, mailx and VM.

The following code should work with both FSF Emacs and XEmacs.

(defvar mail-sent-save-file (concat (getenv "HOME") "/Mail/sent")
  "File in which to save sent mail.")

(defun save-mail-message ()
  (let ((S (buffer-substring (point-min) (point-max))))
    (with-temp-buffer
      (insert (concat "From " user-mail-address "  "
		      (current-time-string) "\n" S "\n"))
      (goto-char (point-min))
      (while (re-search-forward "^--text follows this line--$" nil t)
	(replace-match "" nil t))
      ;; All /^from/i *after* the headers should be escaped
      (while (re-search-forward "^\\([Ff][Rr][Oo][Mm]\\)" nil t)
	(replace-match ">\\1" nil))
      (append-to-file (point-min) (point-max) mail-sent-save-file))))

(add-hook 'mail-send-hook    #'save-mail-message)
(add-hook 'message-send-hook #'save-mail-message)

Log in or register to write something here or to contact authors.