Using Emacs to send mail later

There are lots of ways to schedule mail to be sent some time in the future, but it is easy, for those of us who write and send mail from Emacs, to use that program and the Unix atd batch system to do it. If you use message-mode to write messages, this approach means that creating mails for delayed sending is the same as for normal sending.

Step 1: Write a message in message-mode exactly as normal (a new mail, a reply, whatever). Do C-x C-w to save it to a file, say /tmp/delayed.mail.

Step 2: Put this code in a file, say ~/mylisp/delaymail.el:

(setq send-mail-function (quote sendmail-send-it))

(let ((mailfile (elt argv 0)))
  (if (not (file-exists-p mailfile))
      (error "Mail file %s doesn't exist" mailfile)
    (find-file mailfile)
    ;; Delete the "Date: " line that saving message-mode inserts
    (while (re-search-forward
            "^Date: "
              (re-search-forward "^--text follows this line--")) t)
      (kill-line 1))

This tells Emacs to use sendmail to send the mail, tests for the existence of the file, strips the date-header that message-mode writes when you save, and sends the mail.

Step 3: To send this e-mail at 7:30am do

$ at 07:30
at> emacs --batch -l ~/mylisp/delaymail.el /tmp/delayed.mail
at> ^D

Step 4: Worry about the morality of giving your boss the impression that you’re already working at 7:30am, or hiding from your colleagues that you’re actually sending work e-mails on your own time.