Sending Mail

[previous] [next] [table of contents] [index]

Note: HTML conversion may not be complete.

You may wish to add the following useful key bindings to your .emacs file:

(global-set-key "\C-xm" 'mh-smail)
(global-set-key "\C-x4m" 'mh-smail-other-window)
In addition, several variables are useful when sending mail or replying to mail. They are summarized in the following table.
Variable                    |      Default     |  Description
mh-comp-formfile            |    "components"  |  Format file for
                            |                  |  drafts
mh-repl-formfile            |    "replcomps"   |  Format file for
                            |                  |  replies
mh-letter-mode-hook         |        nil       |  Functions    to
                            |                  |  run    in   MH-
                            |                  |  Letter mode
mh-compose-letter-function  |        nil       |  Functions    to
                            |                  |  run when start-
                            |                  |  ing a new draft
mh-reply-default-reply-to   |        nil       |  Whom reply goes
                            |                  |  to
mh-forward-subject-format   |      "%s: %s"    |  Format   string
                            |                  |  for   forwarded
                            |                  |  message subject
mh-redist-full-contents     |        nil       |  send   requires
                            |                  |  entire message
mh-new-draft-cleaned-headers|  "^Date:\\|      |  Remove    these
                            |  ^Received:\\|   |  header   fields
                            |  ^Message-Id:\\| |  from  re-edited
                            |  ^From:\\|       |  draft
                            |  ^Sender:\\|     |
                            |  ^Delivery-      |
                            |  Date:\\|        |
                            |  ^Return-Path:"  |
Since mh-e does not use comp to create the initial draft, you need to set mh-comp-formfile to the name of your components file if it isn't components. This is the name of the file that contains the form for composing messages. If it does not contain an absolute pathname, mh-e searches for the file first in your MH directory and then in the system MH library directory (such as /usr/local/lib/mh). Replies, on the other hand, are built using repl. You can change the location of the field file from the default of replcomps by modifying mh-repl-formfile.

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 letter. 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 -- all of the other hooks are set in this fashion as well.

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

(defvar letter-mode-init-done nil
  "Non-nil when one-time mh-e settings have made.")

(defun my-mh-letter-mode-hook ()
  "Hook to prepare letter for editing."
  (if (not letter-mode-init-done)                      ; only need to bind the keys once
        ;; add-enriched-text defined in the Example Emacs macros for entering enriched text
        (local-set-key "\C-c\C-tb" 'add-enriched-text)
        (local-set-key "\C-c\C-ti" 'add-enriched-text)
        (local-set-key "\C-c\C-tf" 'add-enriched-text)
        (local-set-key "\C-c\C-ts" 'add-enriched-text)
        (local-set-key "\C-c\C-tB" 'add-enriched-text)
        (local-set-key "\C-c\C-tu" 'add-enriched-text)
        (local-set-key "\C-c\C-tc" 'add-enriched-text)
        (setq letter-mode-init-done t)))
  (setq fill-prefix "  ")                               ; I find indented text easier to read
  (goto-char (point-max))                               ; go to end of message to
  (mh-insert-signature)                                 ; insert signature
  (beginning-of-buffer)                                 ; go to beginning of message
  ;;;  Emacs 19
  (search-forward-regexp "^$"))                         ; and then past header
  ;;;  Emacs 18
  ;;;   (re-search-forward "^$"))

(add-hook 'mh-letter-mode-hook 'my-mh-letter-mode-hook)
If you're using Emacs 18, remove the triple semicolons (;;;) from that line and add them to the start of the line for Emacs 19. The second hook, actually a function, 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.

Replying to Mail

If you find that most of the time that you specify cc when you reply to a message, set mh-reply-default-reply-to to cc . This variable is normally set to nil so that you are prompted for the recipient of a reply. It can be set to one of from , to , or cc ; you are then no longer prompted for the recipient(s) of your reply.

Forwarding Mail

When forwarding a message, the format of the Subject: header field can be modified by the variable mh-forward-subject-format. This variable is a string which includes two escapes (%s). The first %s is replaced with the sender of the original message, and the second one is replaced with the original Subject:. The default value of "%s: %s" takes a message with the header:
To: Bill Wohler <>
Subject: Re: 49er football
From: Greg DesBrisay <>
and creates a subject header field of:
Subject: Greg DesBrisay: Re: 49er football

Redistributing Your Mail

The variable mh-redist-full-contents is set to non-nil if dist requires the whole letter for redistribution, which is the case if send is compiled with the BERK option (which many people abhor). (To see which options your copy of MH was compiled with, use M-x mh-version (the Section Miscellaneous Commands).)

If you find that MH will not allow you to redistribute a message that has been redistributed before, this variable should be set to nil.

Editing Old Drafts and Bounced Messages

The header fields specified by mh-new-draft-cleaned-headers are removed from an old draft that has been recreated with M-e (mh-extract-rejected-mail) or M-a (mh-edit-again). If when you edit an old draft with these commands you find that there are header fields that you don't want included, you can append them to this variable. For example,
(setq mh-new-draft-cleaned-headers
      (concat mh-new-draft-cleaned-headers "\\|^Some-Field:"))
This appends the regular expression \\|^Some-Field: to the variable. The \\| means or, and the ^ (caret) matches the beginning of the line. This is done to be very specific about which fields match. The literal ":" is appended for the same reason.

(To find out more about Emacs' regular expressions, use Info from within Emacs. Type C-h i m emacs RET m regexps RET to get to the right page.)

[Table of Contents] [Index] [Previous: Reading Your Mail] [Next: Editing a Draft]

(This section was written by Bill Wohler.)
Last change $Date: 1996/07/14 17:35:00 $

This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.

Suggestions are welcome: Bill Wohler <>

Questions or problems regarding this web site should be directed to Steve Gielda.
Copyright 1999  All rights reserved.
Last modified: Friday April 02, 1999.