Next: , Up: Sending Mail   [Contents][Index]

8.1 Composing

Outside of an MH-Folder buffer, you must call either M-x mh-smail or M-x mh-smail-other-window to compose a new message. The former command always creates a two-window layout with the current buffer on top and the draft on the bottom. Use the latter command if you would rather preserve the window layout. You may find adding the following key bindings to ~/.emacs useful:

(global-set-key "\C-xm" 'mh-smail)
(global-set-key "\C-x4m" 'mh-smail-other-window)

From within a MH-Folder buffer, you can simply use the command m (mh-send). However you invoke mh-send, your letter appears in an Emacs buffer whose mode is MH-Letter (to see what the buffer looks like, see Sending Mail). MH-Letter mode allows you to edit your message, to check the validity of the recipients, to insert attachments and other messages into your message, and to send the message. We’ll go more into depth about editing a draft29 (a message you’re composing) in just a moment (see Editing a Draft).

If you prefer to be prompted for the recipient and subject fields before the MH-Letter buffer appears, turn on the option mh-compose-prompt-flag.

MH-E adds an ‘X-Mailer:’ header field to the header that includes the version of MH-E and Emacs that you are using. If you don’t want to participate in our marketing, you can turn off the option mh-insert-x-mailer-flag.

Two hooks are provided to run commands on your freshly created draft. The first hook, mh-letter-mode-hook, allows you to do some processing before editing a letter30. For example, you may wish to modify the header after repl has done its work, or you may have a complicated components file and need to tell MH-E where the cursor should go. Here’s an example of how you would use this hook.

(defvar letter-mode-init-done-flag nil
  "Non-nil means one-time MH-E settings have been made.")

(defun my-mh-letter-mode-hook ()
  "Prepare letter for editing."
  (when (not letter-mode-init-done)     ; only need to bind the keys once
    (local-set-key "\C-ctb" 'add-enriched-text)
    (local-set-key "\C-cti" 'add-enriched-text)
    (local-set-key "\C-ctf" 'add-enriched-text)
    (local-set-key "\C-cts" 'add-enriched-text)
    (local-set-key "\C-ctB" 'add-enriched-text)
    (local-set-key "\C-ctu" 'add-enriched-text)
    (local-set-key "\C-ctc" 'add-enriched-text)
    (setq letter-mode-init-done t))
    (goto-char (point-max))             ; go to end of message to
    (mh-insert-signature)))             ;   insert signature

Prepare draft for editing via mh-letter-mode-hook

The function, add-enriched-text is defined in the example in Adding Attachments.

The second hook, a function really, is mh-compose-letter-function. Like mh-letter-mode-hook, it is called just before editing a new message; however, it is the last function called before you edit your message. The consequence of this is that you can write a function to write and send the message for you. This function is passed three arguments: the contents of the ‘To:’, ‘Subject:’, and ‘Cc:’ header fields.



I highly recommend that you use a draft folder so that you can edit several drafts in parallel. To do so, create a folder named ‘+drafts’ for example, and add the profile component ‘Draft-Folder: drafts’ (see mh-profile(5)).


Actually, because MH-Letter mode inherits from Mail mode, the hooks text-mode-hook and mail-mode-hook are run (in that order) before mh-letter-mode-hook.

Next: Replying to Mail, Up: Sending Mail   [Contents][Index]