4

I keep track of my activity in an org-file. The latest status is always under the heading "Current" which I usually just cut and paste into IRC for our weekly meetings. However we are now asked to send the status out ahead of time as an email. I'm trying to work out the best way to create a draft email based on the contents of the an org subtree. Currently I have a babel snippet that will fill the kill-ring but that seems a little hackish. It would be nice to create a complete draft together with address and subject lines.

3
  • If the answer below doesn't solve your problem, please provide more information so that I can update my answer.
    – user2005
    Commented Nov 11, 2014 at 15:48
  • @rekado: I was looking to re-use the existing mu4e email template rather than creating the message from scratch. I guess I wanted to programitically achieve the same as pressing "C" in the mu4e main window
    – stsquad
    Commented Nov 11, 2014 at 16:00
  • 1
    In that case you can use compose-mail; see my updated answer.
    – user2005
    Commented Nov 11, 2014 at 22:18

2 Answers 2

3

You could write a function that copies the subtree to the kill ring, creates a new buffer in message-mode, inserts a couple of lines and pastes the contents of the kill ring, like so:

(defun my-status-as-email ()
  (interactive)

  ;; TODO: copy org subtree to kill ring
  ;; ...

  (set-buffer (get-buffer-create "*draft*"))
  (message-mode)
  (insert "From: me\n")
  (insert "To: you\n")
  (insert "Subject: my status\n")
  (insert "--text follows this line--\n")
  (yank)
  (pop-to-buffer-same-window (current-buffer)))

Alternatively and more elegantly, use compose-mail:

(progn
  (compose-mail "[email protected]" "my subject")
  (insert "my awesome summary:")
  (yank)
  ...)
0

I'm accepting @rekado's answer as he got me there. But here is the org-babel snippet I'm now using for sake of completeness:

#+name: draft-status-email
#+begin_src emacs-lisp 
    (let ((end-of-week
           (chomp
            (shell-command-to-string "date --date='09:00 next Fri' +'%b. %e %Y'"))))
      (save-excursion
        (goto-char (point-min))
        (re-search-forward "** Current")
        (org-copy-subtree)
        (kill-whole-line)
        (insert (format "** Team Email %s\n" (format-time-string "%e/%m/%Y"))))
      (compose-mail
       "[email protected]"
       (format "[weekly] week ending %s" end-of-week)
       nil
       t)
      (insert "Summary of activity:\n")
      (yank 2))
#+end_src

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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