{"id":236,"date":"2014-01-27T23:05:23","date_gmt":"2014-01-27T23:05:23","guid":{"rendered":"http:\/\/teaching.sociology.ul.ie\/bhalpin\/wordpress\/?p=236"},"modified":"2014-04-19T14:46:06","modified_gmt":"2014-04-19T14:46:06","slug":"using-emacs-to-send-mail-later","status":"publish","type":"post","link":"https:\/\/teaching.sociology.ul.ie\/bhalpin\/wordpress\/?p=236","title":{"rendered":"Using Emacs to send mail later"},"content":{"rendered":"<p>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 <code>atd<\/code> batch system to do it. If you use <code>message-mode<\/code> to write messages, this approach means that creating mails for delayed sending is the same as for normal sending.<\/p>\n<p><!--more--><\/p>\n<p>Step 1: Write a message in <code>message-mode<\/code> exactly as normal (a new mail, a reply, whatever). Do <code>C-x C-w<\/code> to save it to a file, say <code>\/tmp\/delayed.mail<\/code>.<\/p>\n<p>Step 2: Put this code in a file, say <code>~\/mylisp\/delaymail.el<\/code>:<\/p>\n<pre>(setq send-mail-function (quote sendmail-send-it))\r\n\r\n(let ((mailfile (elt argv 0)))\r\n  (if (not (file-exists-p mailfile))\r\n      (error \"Mail file %s doesn't exist\" mailfile)\r\n    (find-file mailfile)\r\n    ;; Delete the \"Date: \" line that saving message-mode inserts\r\n    (while (re-search-forward\r\n            \"^Date: \"\r\n            (save-excursion\r\n              (re-search-forward \"^--text follows this line--\")) t)\r\n      (beginning-of-line)\r\n      (kill-line 1))\r\n    (message-mode)\r\n    (message-send-and-exit)))<\/pre>\n<p>This tells Emacs to use <code>sendmail<\/code> to send the mail, tests for the existence of the file, strips the date-header that <code>message-mode<\/code> writes when you save, and sends the mail.<\/p>\n<p>Step 3: To send this e-mail at 7:30am do<\/p>\n<pre>$ at 07:30\r\nat&gt; emacs --batch -l ~\/mylisp\/delaymail.el \/tmp\/delayed.mail\r\nat&gt; ^D\r\n$<\/pre>\n<p>Step 4: Worry about the morality of giving your boss the impression that you&#8217;re already working at 7:30am, or hiding from your colleagues that you&#8217;re actually sending work e-mails on your own time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"https:\/\/teaching.sociology.ul.ie\/bhalpin\/wordpress\/?p=236\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Using Emacs to send mail later<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/teaching.sociology.ul.ie\/bhalpin\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/236"}],"collection":[{"href":"https:\/\/teaching.sociology.ul.ie\/bhalpin\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/teaching.sociology.ul.ie\/bhalpin\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/teaching.sociology.ul.ie\/bhalpin\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/teaching.sociology.ul.ie\/bhalpin\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=236"}],"version-history":[{"count":7,"href":"https:\/\/teaching.sociology.ul.ie\/bhalpin\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/236\/revisions"}],"predecessor-version":[{"id":257,"href":"https:\/\/teaching.sociology.ul.ie\/bhalpin\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/236\/revisions\/257"}],"wp:attachment":[{"href":"https:\/\/teaching.sociology.ul.ie\/bhalpin\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/teaching.sociology.ul.ie\/bhalpin\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/teaching.sociology.ul.ie\/bhalpin\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}