tags:

views:

392

answers:

1

Is there a way to build up an email message from a region or buffer, set up a recipient and then send a message in elisp code?

I've configured emacs to send mail via my gmail account and I'd like to be able to send myself emails from elisp programs. The command used is message-mail.

+3  A: 

Here's a wrapper for message-mail that prompts you for the 'to' and 'subject' lines:

(defun my-message-mail-region (b e to subject)
  "Send the current region in an email"
  (interactive "r\nsRecipient: \nsSubject: ")
  (let ((orig-buffer (current-buffer)))
    (message-mail to subject)
    (message-goto-body)
    (insert (save-excursion (set-buffer orig-buffer)
                            (buffer-substring-no-properties b e)))
    (message-send-and-exit)))
Trey Jackson