Go to the first, previous, next, last section, table of contents.
To send a message in Emacs, you start by typing a command (C-x m) to select and initialize the `*mail*' buffer. Then you edit the text and headers of the message in this buffer, and type another command (C-c C-s or C-c C-c) to send the message.
compose-mail
).
compose-mail-other-window
).
compose-mail-other-frame
).
mail-send
).
mail-send-and-exit
).
The command C-x m (compose-mail
) selects a buffer named
`*mail*' and initializes it with the skeleton of an outgoing
message. C-x 4 m (compose-mail-other-window
) selects the
`*mail*' buffer in a different window, leaving the previous current
buffer visible. C-x 5 m (compose-mail-other-frame
) creates
a new frame to select the `*mail*' buffer.
Because the mail-composition buffer is an ordinary Emacs buffer, you can switch to other buffers while in the middle of composing mail, and switch back later (or never). If you use the C-x m command again when you have been composing another message but have not sent it, you are asked to confirm before the old message is erased. If you answer n, the `*mail*' buffer is left selected with its old contents, so you can finish the old message and send it. C-u C-x m is another way to do this. Sending the message marks the `*mail*' buffer "unmodified," which avoids the need for confirmation when C-x m is next used.
If you are composing a message in the `*mail*' buffer and want to send another message before finishing the first, rename the `*mail*' buffer using M-x rename-uniquely (see section Miscellaneous Buffer Operations). Then you can use C-x m or its variants described above to make a new `*mail*' buffer. Once you've done that, you can work with each mail buffer independently.
In addition to the text or body, a message has header fields which say who sent it, when, to whom, why, and so on. Some header fields, such as `Date' and `Sender', are created automatically when you send the message. Others, such as the recipient names, must be specified by you in order to send the message properly.
Mail mode provides a few commands to help you edit some header fields, and some are preinitialized in the buffer automatically at times. You can insert and edit header fields using ordinary editing commands.
The line in the buffer that says
--text follows this line--
is a special delimiter that separates the headers you have specified from
the text. Whatever follows this line is the text of the message; the
headers precede it. The delimiter line itself does not appear in the
message actually sent. The text used for the delimiter line is controlled
by the variable mail-header-separator
.
Here is an example of what the headers and text in the mail buffer might look like.
To: gnu@gnu.org CC: lungfish@spam.org, byob@spam.org Subject: The Emacs Manual --Text follows this line-- Please ignore this message.
A header field in the mail buffer starts with a field name at the beginning of a line, terminated by a colon. Upper and lower case are equivalent in field names (and in mailing addresses also). After the colon and optional whitespace comes the contents of the field.
You can use any name you like for a header field, but normally people use only standard field names with accepted meanings. Here is a table of fields commonly used in outgoing messages.
mail-self-blind
to t
.
mail-archive-file-name
to that file name. Unless you remove the
`FCC' field before sending, the message will be written into that
file when it is sent.
user-mail-address
as the default.
mail-default-reply-to
to that address (as a string).
Then mail
initializes the message with a `Reply-to' field as
specified. You can delete or alter that header field before you send
the message, if you wish. When Emacs starts up, if the environment
variable REPLYTO
is set, mail-default-reply-to
is
initialized from that environment variable.
The `To', `CC', `BCC' and `FCC' header fields can appear any number of times, and each such header field can contain multiple addresses, separated by commas. This way, you can specify any number of places to send the message. A `To', `CC', or `BCC' field can also have continuation lines: one or more lines starting with whitespace, following the starting line of the field, are considered part of the field. Here's an example of a `To' field with a continuation line:
To: foo@here.net, this@there.net, me@gnu.cambridge.mass.usa.earth.spiral3281
When you send the message, if you didn't write a `From' field
yourself, Emacs puts in one for you. The variable
mail-from-style
controls the format:
nil
parens
angles
system-default
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
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-setup-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-setup-hook '(lambda () (substitute-key-definition 'next-line 'mail-abbrev-next-line mail-mode-map global-map) (substitute-key-definition 'end-of-buffer 'mail-abbrev-end-of-buffer mail-mode-map global-map)))
The major mode used in the mail buffer is Mail mode, which is much like Text mode except that various special commands are provided on the C-c prefix. These commands all have to do specifically with editing or sending the message. In addition, Mail mode defines the character `%' as a word separator; this is helpful for using the word commands to edit mail addresses.
Mail mode is normally used in buffers set up automatically by the
mail
command and related commands. However, you can also switch
to Mail mode in a file-visiting buffer. That is a useful thing to do if
you have saved draft message text in a file.
Mail mode has two commands for sending the message you have been editing:
mail-send
).
mail-send-and-exit
).
C-c C-s (mail-send
) sends the message and marks the mail
buffer unmodified, but leaves that buffer selected so that you can
modify the message (perhaps with new recipients) and send it again.
C-c C-c (mail-send-and-exit
) sends and then deletes the
window or switches to another buffer. It puts the mail buffer at the
lowest priority for reselection by default, since you are finished with
using it. This is the usual way to send the message.
In a file-visiting buffer, sending the message does not clear the modified flag, because only saving the file should do that. As a result, you don't get a warning if you try to send the same message twice.
When you send a message that contains non-ASCII characters, they need
to be encoded with a coding system (see section Coding Systems). Usually
the coding system is specified automatically by your chosen language
environment (see section Language Environments). You can explicitly specify
the coding system for outgoing mail by setting the variable
sendmail-coding-system
.
If the coding system thus determined does not handle the characters in a particular message, Emacs asks you to select the coding system to use, showing a list of possible coding systems.
Mail mode provides special commands to move to particular header fields and to complete addresses in headers.
mail-to
).
mail-subject
).
mail-cc
).
mail-bcc
).
mail-fcc
).
mail-complete
).
There are five commands to move point to particular header fields, all based on the prefix C-c C-f (`C-f' is for "field"). They are listed in the table above. If the field in question does not exist, these commands create one. We provide special motion commands for these particular fields because they are the fields users most often want to edit.
While editing a header field that contains mailing addresses, such as
`To:', `CC:' and `BCC:', you can complete a mailing
address by typing M-TAB (mail-complete
). It inserts
the full name corresponding to the address, if it can determine the full
name. The variable mail-complete-style
controls whether to insert
the full name, and what style to use, as in mail-from-style
(see section Mail Header Fields).
For completion purposes, the valid mailing addresses are taken to be the local users' names plus your personal mail aliases. You can specify additional sources of valid addresses; use the customization buffer to see the options for this.
If you type M-TAB in the body of the message, it invokes
ispell-complete-word
, as in Text mode.
Mail mode also has commands for yanking or citing all or part of a message that you are replying to. These commands are active only when you started sending a message using an Rmail command.
mail-yank-original
).
mail-yank-region
).
mail-fill-yanked-message
).
When mail sending is invoked from the Rmail mail reader using an Rmail command, C-c C-y can be used inside the mail buffer to insert the text of the message you are replying to. Normally it indents each line of that message three spaces and eliminates most header fields. A numeric argument specifies the number of spaces to indent. An argument of just C-u says not to indent at all and not to eliminate anything. C-c C-y always uses the current message from the Rmail buffer, so you can insert several old messages by selecting one in Rmail, switching to `*mail*' and yanking it, then switching back to Rmail to select another.
You can specify the text for C-c C-y to insert at the beginning
of each line: set mail-yank-prefix
to the desired string. (A
value of nil
means to use indentation; this is the default.)
However, C-u C-c C-y never adds anything at the beginning of the
inserted lines, regardless of the value of mail-yank-prefix
.
To yank just a part of an incoming message, set the region in Rmail to
the part you want; then go to the `*Mail*' message and type
C-c C-r (mail-yank-region
). Each line that is copied is
indented or prefixed according to mail-yank-prefix
.
After using C-c C-y or C-c C-r, you can type C-c C-q
(mail-fill-yanked-message
) to fill the paragraphs of the yanked
old message or messages. One use of C-c C-q fills all such
paragraphs, each one individually. To fill a single paragraph of the
quoted message, use M-q. If filling does not automatically
handle the type of citation prefix you use, try setting the fill prefix
explicitly. See section Filling Text.
mail-text
).
mail-signature
).
mail-attach-file
).
C-c C-t (mail-text
) moves point to just after the header
separator line--that is, to the beginning of the message body text.
C-c C-w (mail-signature
) adds a standard piece of text at
the end of the message to say more about who you are. The text comes
from the file `~/.signature' in your home directory. To insert
your signature automatically, set the variable mail-signature
to
t
; then starting a mail message automatically inserts the
contents of your `~/.signature' file. If you want to omit your
signature from a particular message, delete it from the buffer before
you send the message.
You can also set mail-signature
to a string; then that string
is inserted automatically as your signature when you start editing a
message to send. If you set it to some other Lisp expression, the
expression is evaluated each time, and its value (which should be a
string) specifies the signature.
You can do spelling correction on the message text you have written
with the command M-x ispell-message. If you have yanked an
incoming message into the outgoing draft, this command skips what was
yanked, but it checks the text that you yourself inserted. (It looks
for indentation or mail-yank-prefix
to distinguish the cited
lines from your input.) See section Checking and Correcting Spelling.
To include a file in the outgoing message, you can use C-x i,
the usual command to insert a file in the current buffer. But it is
often more convenient to use a special command, C-c C-i
(mail-attach-file
). This command inserts the file contents at
the end of the buffer, after your signature if any, with a delimiter
line that includes the file name.
Turning on Mail mode (which C-x m does automatically) runs the
normal hooks text-mode-hook
and mail-mode-hook
.
Initializing a new outgoing message runs the normal hook
mail-setup-hook
; if you want to add special fields to your mail
header or make other changes to the appearance of the mail buffer, use
that hook. See section Hooks.
The main difference between these hooks is just when they are
invoked. Whenever you type M-x mail, mail-mode-hook
runs
as soon as the `*mail*' buffer is created. Then the
mail-setup
function puts in the default contents of the buffer.
After these default contents are inserted, mail-setup-hook
runs.
M-x spook adds a line of randomly chosen keywords to an outgoing mail message. The keywords are chosen from a list of words that suggest you are discussing something subversive.
The idea behind this feature is the suspicion that the NSA snoops on all electronic mail messages that contain keywords suggesting they might find them interesting. (The NSA says they don't, but that's what they would say.) The idea is that if lots of people add suspicious words to their messages, the NSA will get so busy with spurious input that they will have to give up reading it all.
Here's how to insert spook keywords automatically whenever you start entering an outgoing message:
(add-hook 'mail-setup-hook 'spook)
Whether or not this confuses the NSA, it at least amuses people.
This chapter describes the usual Emacs mode for editing and sending
mail--Mail mode. Emacs has alternative facilities for editing and
sending mail, including MH-E and Message mode, not documented in this
manual. You can choose any of them as your preferred method. The
commands C-x m
, C-x 4 m
and C-x 5 m
use whichever
agent you have specified. So do various other Emacs commands and
facilities that send mail.
To specify your mail-composition method, set the variable
mail-user-agent
. Currently legitimate values include
sendmail-user-agent
, mh-e-user-agent
, and
message-user-agent
.
If you select a different mail-composition method, the information in this chapter about the `*mail*' buffer and Mail mode does not apply; other methods may use completely different commands with a different format in a differently named buffer.
Go to the first, previous, next, last section, table of contents.