manpagez: man pages & more
info emacs
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

36.3 Mail Aliases

You can define mail aliases in a file named ‘~/.mailrc’. These are short mnemonic names which stand for mail addresses or groups of mail addresses. Like many other mail programs, Emacs expands aliases when they occur in the ‘To’, ‘From’, ‘CC’, ‘BCC’, and ‘Reply-to’ fields, plus their ‘Resent-’ variants.

To define an alias in ‘~/.mailrc’, write a line in the following format:

 
alias shortaddress fulladdresses

Here fulladdresses stands for one or more mail addresses for shortaddress to expand into. Separate multiple addresses with spaces; if an address contains a space, quote the whole address with a pair of double-quotes.

For instance, to make maingnu stand for gnu@gnu.org plus a local address of your own, put in this line:

 
alias maingnu gnu@gnu.org local-gnu

Addresses specified in this way should use doublequotes around an entire address when the address contains spaces. But you need not include doublequotes around parts of the address, such as the person's full name. Emacs puts them in if they are needed. For example,

 
alias chief-torturer "George W. Bush <bush@whitehouse.gov>"

is correct in ‘.mailrc’. Emacs will insert the address as ‘"George W. Bush" <bush@whitehouse.gov>’.

Emacs also recognizes “include” commands in ‘.mailrc’ files. They look like this:

 
source filename

The file ‘~/.mailrc’ is used primarily by other mail-reading programs; it can contain various other commands. Emacs ignores everything in it except for alias definitions and include commands.

Another way to define a mail alias, within Emacs alone, is with the define-mail-alias command. It prompts for the alias and then the full address. You can use it to define aliases in your ‘.emacs’ file, like this:

 
(define-mail-alias "maingnu" "gnu@gnu.org")

define-mail-alias records aliases by adding them to a variable named mail-aliases. If you are comfortable with manipulating Lisp lists, you can set mail-aliases directly. The initial value of mail-aliases is t, which means that Emacs should read ‘.mailrc’ to get the proper value.

You can specify a different file name to use instead of ‘~/.mailrc’ by setting the variable mail-personal-alias-file.

Normally, Emacs expands aliases when you send the message. You do not need to expand mail aliases before sending the message, but you can expand them if you want to see where the mail will actually go. To do this, use the command M-x expand-mail-aliases; it expands all mail aliases currently present in the mail headers that hold addresses.

If you like, you can have mail aliases expand as abbrevs, as soon as you type them in (see section Abbrevs). To enable this feature, execute the following:

 
(add-hook 'mail-mode-hook 'mail-abbrevs-setup)

This can go in your ‘.emacs’ file. See section Hooks. If you use this feature, you must use define-mail-abbrev instead of define-mail-alias; the latter does not work with this package. Note that the mail abbreviation package uses the variable mail-abbrevs instead of mail-aliases, and that all alias names are converted to lower case.

The mail abbreviation package also provides the C-c C-a (mail-interactive-insert-alias) command, which reads an alias name (with completion) and inserts its definition at point. This is useful when editing the message text itself or a header field such as ‘Subject’ in which Emacs does not normally expand aliases.

Note that abbrevs expand only if you insert a word-separator character afterward. However, you can rebind C-n and M-> to cause expansion as well. Here's how to do that:

 
(add-hook 'mail-mode-hook
    (lambda ()
      (define-key
        mail-mode-map [remap next-line] 'mail-abbrev-next-line)
      (define-key
        mail-mode-map [remap end-of-buffer] 'mail-abbrev-end-of-buffer)))

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.