2

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.

2

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)
  • 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
2

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))))
  • 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
1

I use more complicate solution:

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

(defun my-clean-filename (filename)
  (mapconcat
   (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.

  • "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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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