(ibuffer-set-mark): Go back to the beginning of the line after setting
[bpt/emacs.git] / man / sending.texi
CommitLineData
6bf7aab6 1@c This is part of the Emacs manual.
739a80b3 2@c Copyright (C) 1985,86,87,93,94,95,97,2000,2001
6ca0edfe 3@c Free Software Foundation, Inc.
6bf7aab6
DL
4@c See file emacs.texi for copying conditions.
5@node Sending Mail, Rmail, Picture, Top
6@chapter Sending Mail
7@cindex sending mail
8@cindex mail
9@cindex message
10
11 To send a message in Emacs, you start by typing a command (@kbd{C-x m})
12to select and initialize the @samp{*mail*} buffer. Then you edit the text
13and headers of the message in this buffer, and type another command
14(@kbd{C-c C-s} or @kbd{C-c C-c}) to send the message.
15
16@table @kbd
17@item C-x m
18Begin composing a message to send (@code{compose-mail}).
19@item C-x 4 m
20Likewise, but display the message in another window
21(@code{compose-mail-other-window}).
22@item C-x 5 m
23Likewise, but make a new frame (@code{compose-mail-other-frame}).
24@item C-c C-s
25In Mail mode, send the message (@code{mail-send}).
26@item C-c C-c
27Send the message and bury the mail buffer (@code{mail-send-and-exit}).
28@end table
29
30@kindex C-x m
31@findex compose-mail
32@kindex C-x 4 m
33@findex compose-mail-other-window
34@kindex C-x 5 m
35@findex compose-mail-other-frame
36 The command @kbd{C-x m} (@code{compose-mail}) selects a buffer named
37@samp{*mail*} and initializes it with the skeleton of an outgoing
38message. @kbd{C-x 4 m} (@code{compose-mail-other-window}) selects the
39@samp{*mail*} buffer in a different window, leaving the previous current
40buffer visible. @kbd{C-x 5 m} (@code{compose-mail-other-frame}) creates
41a new frame to select the @samp{*mail*} buffer.
42
43 Because the mail-composition buffer is an ordinary Emacs buffer, you can
44switch to other buffers while in the middle of composing mail, and switch
45back later (or never). If you use the @kbd{C-x m} command again when you
46have been composing another message but have not sent it, you are asked to
47confirm before the old message is erased. If you answer @kbd{n}, the
48@samp{*mail*} buffer is left selected with its old contents, so you can
49finish the old message and send it. @kbd{C-u C-x m} is another way to do
50this. Sending the message marks the @samp{*mail*} buffer ``unmodified,''
51which avoids the need for confirmation when @kbd{C-x m} is next used.
52
53 If you are composing a message in the @samp{*mail*} buffer and want to
54send another message before finishing the first, rename the
55@samp{*mail*} buffer using @kbd{M-x rename-uniquely} (@pxref{Misc
56Buffer}). Then you can use @kbd{C-x m} or its variants described above
57to make a new @samp{*mail*} buffer. Once you've done that, you can work
58with each mail buffer independently.
59
2e2cdb68
RS
60@ignore
61@c Commented out because it is not user-oriented;
62@c it doesn't say how to do some job. -- rms.
c016c701
DL
63@cindex directory servers
64@cindex LDAP
65@cindex PH/QI
66@cindex names and addresses
67There is an interface to directory servers using various protocols such
68as LDAP or the CCSO white pages directory system (PH/QI), described in a
69separate manual. It may be useful for looking up names and addresses.
70@xref{Top,,EUDC, eudc, EUDC Manual}.
2e2cdb68 71@end ignore
c016c701 72
6bf7aab6
DL
73@menu
74* Format: Mail Format. Format of the mail being composed.
75* Headers: Mail Headers. Details of permitted mail header fields.
76* Aliases: Mail Aliases. Abbreviating and grouping mail addresses.
77* Mode: Mail Mode. Special commands for editing mail being composed.
2e2cdb68 78* Amuse: Mail Amusements. Distracting the NSA; adding fortune messages.
2394fd21 79* Methods: Mail Methods. Using alternative mail-composition methods.
6bf7aab6
DL
80@end menu
81
82@node Mail Format
83@section The Format of the Mail Buffer
84
85 In addition to the @dfn{text} or @dfn{body}, a message has @dfn{header
86fields} which say who sent it, when, to whom, why, and so on. Some
87header fields, such as @samp{Date} and @samp{Sender}, are created
88automatically when you send the message. Others, such as the recipient
89names, must be specified by you in order to send the message properly.
90
91 Mail mode provides a few commands to help you edit some header fields,
92and some are preinitialized in the buffer automatically at times. You can
93insert and edit header fields using ordinary editing commands.
94
95 The line in the buffer that says
96
97@example
98--text follows this line--
99@end example
100
101@noindent
102is a special delimiter that separates the headers you have specified from
103the text. Whatever follows this line is the text of the message; the
104headers precede it. The delimiter line itself does not appear in the
105message actually sent. The text used for the delimiter line is controlled
106by the variable @code{mail-header-separator}.
107
108Here is an example of what the headers and text in the mail buffer
109might look like.
110
111@example
112To: gnu@@gnu.org
113CC: lungfish@@spam.org, byob@@spam.org
114Subject: The Emacs Manual
115--Text follows this line--
116Please ignore this message.
117@end example
118
119@node Mail Headers
120@section Mail Header Fields
121@cindex headers (of mail message)
122
123 A header field in the mail buffer starts with a field name at the
124beginning of a line, terminated by a colon. Upper and lower case are
125equivalent in field names (and in mailing addresses also). After the
126colon and optional whitespace comes the contents of the field.
127
128 You can use any name you like for a header field, but normally people
129use only standard field names with accepted meanings. Here is a table
130of fields commonly used in outgoing messages.
131
132@table @samp
133@item To
134This field contains the mailing addresses to which the message is
135addressed. If you list more than one address, use commas, not spaces,
136to separate them.
137
138@item Subject
139The contents of the @samp{Subject} field should be a piece of text
140that says what the message is about. The reason @samp{Subject} fields
141are useful is that most mail-reading programs can provide a summary of
142messages, listing the subject of each message but not its text.
143
144@item CC
145This field contains additional mailing addresses to send the message to,
146like @samp{To} except that these readers should not regard the message
147as directed at them.
148
149@item BCC
150This field contains additional mailing addresses to send the message to,
151which should not appear in the header of the message actually sent.
152Copies sent this way are called @dfn{blind carbon copies}.
153
154@vindex mail-self-blind
c7fa86d5 155@cindex copy of every outgoing message
6bf7aab6 156To send a blind carbon copy of every outgoing message to yourself, set
c7fa86d5
EZ
157the variable @code{mail-self-blind} to @code{t}. To send a blind carbon
158copy of every message to some other @var{address}, set the variable
2e2cdb68 159@code{mail-default-headers} to @code{"Bcc: @var{address}\n"}.
6bf7aab6
DL
160
161@item FCC
162This field contains the name of one file and directs Emacs to append a
163copy of the message to that file when you send the message. If the file
164is in Rmail format, Emacs writes the message in Rmail format; otherwise,
7fc1fe09
RS
165Emacs writes the message in system mail file format. To specify
166more than one file, use several @samp{FCC} fields, with one file
167name in each field.
6bf7aab6
DL
168
169@vindex mail-archive-file-name
170To put a fixed file name in the @samp{FCC} field each time you start
171editing an outgoing message, set the variable
172@code{mail-archive-file-name} to that file name. Unless you remove the
173@samp{FCC} field before sending, the message will be written into that
174file when it is sent.
175
176@item From
177Use the @samp{From} field to say who you are, when the account you are
178using to send the mail is not your own. The contents of the @samp{From}
179field should be a valid mailing address, since replies will normally go
180there. If you don't specify the @samp{From} field yourself, Emacs uses
181the value of @code{user-mail-address} as the default.
182
183@item Reply-to
184Use this field to direct replies to a different address. Most
185mail-reading programs (including Rmail) automatically send replies to
186the @samp{Reply-to} address in preference to the @samp{From} address.
187By adding a @samp{Reply-to} field to your header, you can work around
188any problems your @samp{From} address may cause for replies.
189
60a96371 190@cindex @env{REPLYTO} environment variable
6bf7aab6
DL
191@vindex mail-default-reply-to
192To put a fixed @samp{Reply-to} address into every outgoing message, set
193the variable @code{mail-default-reply-to} to that address (as a string).
194Then @code{mail} initializes the message with a @samp{Reply-to} field as
195specified. You can delete or alter that header field before you send
196the message, if you wish. When Emacs starts up, if the environment
60a96371 197variable @env{REPLYTO} is set, @code{mail-default-reply-to} is
6bf7aab6
DL
198initialized from that environment variable.
199
200@item In-reply-to
58fa012d 201This field contains a piece of text describing the message you are
6bf7aab6
DL
202replying to. Some mail systems can use this information to correlate
203related pieces of mail. Normally this field is filled in by Rmail
204when you reply to a message in Rmail, and you never need to
205think about it (@pxref{Rmail}).
206
207@item References
208This field lists the message IDs of related previous messages. Rmail
209sets up this field automatically when you reply to a message.
210@end table
211
7fc1fe09
RS
212 The @samp{To}, @samp{CC}, and @samp{BCC} header fields can appear
213any number of times, and each such header field can contain multiple
214addresses, separated by commas. This way, you can specify any number
215of places to send the message. These fields can also have
216continuation lines: one or more lines starting with whitespace,
217following the starting line of the field, are considered part of the
218field. Here's an example of a @samp{To} field with a continuation
219line:@refill
6bf7aab6
DL
220
221@example
222@group
223To: foo@@here.net, this@@there.net,
224 me@@gnu.cambridge.mass.usa.earth.spiral3281
225@end group
226@end example
227
228@vindex mail-from-style
229 When you send the message, if you didn't write a @samp{From} field
230yourself, Emacs puts in one for you. The variable
231@code{mail-from-style} controls the format:
232
233@table @code
234@item nil
235Use just the email address, as in @samp{king@@grassland.com}.
236@item parens
237Use both email address and full name, as in @samp{king@@grassland.com (Elvis
238Parsley)}.
239@item angles
240Use both email address and full name, as in @samp{Elvis Parsley
241<king@@grassland.com>}.
242@item system-default
243Allow the system to insert the @samp{From} field.
244@end table
245
c7fa86d5 246@vindex mail-default-headers
2e2cdb68
RS
247 You can direct Emacs to insert certain default headers into the
248outgoing message by setting the variable @code{mail-default-headers}
249to a string. Then @code{C-x m} inserts this string into the message
250headers. If the default header fields are not appropriate for a
251particular message, edit them as appropriate before sending the
252message.
c7fa86d5 253
6bf7aab6
DL
254@node Mail Aliases
255@section Mail Aliases
256@cindex mail aliases
257@cindex @file{.mailrc} file
258@cindex mailrc file
259
260 You can define @dfn{mail aliases} in a file named @file{~/.mailrc}.
261These are short mnemonic names which stand for mail addresses or groups of
262mail addresses. Like many other mail programs, Emacs expands aliases
263when they occur in the @samp{To}, @samp{From}, @samp{CC}, @samp{BCC}, and
264@samp{Reply-to} fields, plus their @samp{Resent-} variants.
265
266 To define an alias in @file{~/.mailrc}, write a line in the following
267format:
268
269@example
270alias @var{shortaddress} @var{fulladdresses}
271@end example
272
273@noindent
274Here @var{fulladdresses} stands for one or more mail addresses for
275@var{shortaddress} to expand into. Separate multiple addresses with
276spaces; if an address contains a space, quote the whole address with a
277pair of double-quotes.
278
279For instance, to make @code{maingnu} stand for
280@code{gnu@@gnu.org} plus a local address of your own, put in
281this line:@refill
282
283@example
284alias maingnu gnu@@gnu.org local-gnu
285@end example
286
287 Emacs also recognizes include commands in @samp{.mailrc} files.
288They look like this:
289
290@example
291source @var{filename}
292@end example
293
294@noindent
295The file @file{~/.mailrc} is used primarily by other mail-reading
296programs; it can contain various other commands. Emacs ignores
297everything in it except for alias definitions and include commands.
298
299@findex define-mail-alias
300 Another way to define a mail alias, within Emacs alone, is with the
301@code{define-mail-alias} command. It prompts for the alias and then the
302full address. You can use it to define aliases in your @file{.emacs}
303file, like this:
304
305@example
306(define-mail-alias "maingnu" "gnu@@gnu.org")
307@end example
308
309@vindex mail-aliases
310 @code{define-mail-alias} records aliases by adding them to a
311variable named @code{mail-aliases}. If you are comfortable with
312manipulating Lisp lists, you can set @code{mail-aliases} directly. The
313initial value of @code{mail-aliases} is @code{t}, which means that
314Emacs should read @file{.mailrc} to get the proper value.
315
316@vindex mail-personal-alias-file
317 You can specify a different file name to use instead of
318@file{~/.mailrc} by setting the variable
319@code{mail-personal-alias-file}.
320
321@findex expand-mail-aliases
322 Normally, Emacs expands aliases when you send the message. You do not
323need to expand mail aliases before sending the message, but you can
324expand them if you want to see where the mail will actually go. To do
325this, use the command @kbd{M-x expand-mail-aliases}; it expands all mail
326aliases currently present in the mail headers that hold addresses.
327
328 If you like, you can have mail aliases expand as abbrevs, as soon as
329you type them in (@pxref{Abbrevs}). To enable this feature, execute the
330following:
331
332@example
49172314 333(add-hook 'mail-mode-hook 'mail-abbrevs-setup)
6bf7aab6
DL
334@end example
335
336@noindent
337@findex define-mail-abbrev
338@vindex mail-abbrevs
339This can go in your @file{.emacs} file. @xref{Hooks}. If you use this
340feature, you must use @code{define-mail-abbrev} instead of
341@code{define-mail-alias}; the latter does not work with this package.
342Note that the mail abbreviation package uses the variable
343@code{mail-abbrevs} instead of @code{mail-aliases}, and that all alias
344names are converted to lower case.
345
346@kindex C-c C-a @r{(Mail mode)}
347@findex mail-interactive-insert-alias
348 The mail abbreviation package also provides the @kbd{C-c C-a}
349(@code{mail-interactive-insert-alias}) command, which reads an alias
350name (with completion) and inserts its definition at point. This is
351useful when editing the message text itself or a header field such as
352@samp{Subject} in which Emacs does not normally expand aliases.
353
354 Note that abbrevs expand only if you insert a word-separator character
355afterward. However, you can rebind @kbd{C-n} and @kbd{M->} to cause
356expansion as well. Here's how to do that:
357
358@smallexample
49172314 359(add-hook 'mail-mode-hook
43aef553
SM
360 (lambda ()
361 (substitute-key-definition
362 'next-line 'mail-abbrev-next-line
363 mail-mode-map global-map)
364 (substitute-key-definition
365 'end-of-buffer 'mail-abbrev-end-of-buffer
366 mail-mode-map global-map)))
6bf7aab6
DL
367@end smallexample
368
369@node Mail Mode
370@section Mail Mode
371@cindex Mail mode
372@cindex mode, Mail
373
374 The major mode used in the mail buffer is Mail mode, which is much
375like Text mode except that various special commands are provided on the
376@kbd{C-c} prefix. These commands all have to do specifically with
377editing or sending the message. In addition, Mail mode defines the
378character @samp{%} as a word separator; this is helpful for using the
379word commands to edit mail addresses.
380
381 Mail mode is normally used in buffers set up automatically by the
382@code{mail} command and related commands. However, you can also switch
58fa012d
EZ
383to Mail mode in a file-visiting buffer. This is a useful thing to do if
384you have saved the text of a draft message in a file.
6bf7aab6
DL
385
386@menu
387* Mail Sending:: Commands to send the message.
388* Header Editing:: Commands to move to header fields and edit them.
389* Citing Mail:: Copying all or part of a message you are replying to.
390* Mail Mode Misc:: Spell checking, signatures, etc.
391@end menu
392
393@node Mail Sending
394@subsection Mail Sending
395
396 Mail mode has two commands for sending the message you have been
397editing:
398
399@table @kbd
400@item C-c C-s
401Send the message, and leave the mail buffer selected (@code{mail-send}).
402@item C-c C-c
403Send the message, and select some other buffer (@code{mail-send-and-exit}).
404@end table
405
406@kindex C-c C-s @r{(Mail mode)}
407@kindex C-c C-c @r{(Mail mode)}
408@findex mail-send
409@findex mail-send-and-exit
410 @kbd{C-c C-s} (@code{mail-send}) sends the message and marks the mail
411buffer unmodified, but leaves that buffer selected so that you can
412modify the message (perhaps with new recipients) and send it again.
413@kbd{C-c C-c} (@code{mail-send-and-exit}) sends and then deletes the
414window or switches to another buffer. It puts the mail buffer at the
415lowest priority for reselection by default, since you are finished with
416using it. This is the usual way to send the message.
417
418 In a file-visiting buffer, sending the message does not clear the
419modified flag, because only saving the file should do that. As a
420result, you don't get a warning if you try to send the same message
421twice.
422
4946337d
EZ
423@c This is indexed in mule.texi, node "Recognize Coding".
424@c @vindex sendmail-coding-system
6bf7aab6
DL
425 When you send a message that contains non-ASCII characters, they need
426to be encoded with a coding system (@pxref{Coding Systems}). Usually
427the coding system is specified automatically by your chosen language
428environment (@pxref{Language Environments}). You can explicitly specify
429the coding system for outgoing mail by setting the variable
4946337d 430@code{sendmail-coding-system} (@pxref{Recognize Coding}).
6bf7aab6
DL
431
432 If the coding system thus determined does not handle the characters in
433a particular message, Emacs asks you to select the coding system to use,
434showing a list of possible coding systems.
435
436@node Header Editing
437@subsection Mail Header Editing
438
439 Mail mode provides special commands to move to particular header
440fields and to complete addresses in headers.
441
442@table @kbd
443@item C-c C-f C-t
444Move to the @samp{To} header field, creating one if there is none
445(@code{mail-to}).
446@item C-c C-f C-s
447Move to the @samp{Subject} header field, creating one if there is
448none (@code{mail-subject}).
449@item C-c C-f C-c
450Move to the @samp{CC} header field, creating one if there is none
451(@code{mail-cc}).
452@item C-c C-f C-b
453Move to the @samp{BCC} header field, creating one if there is none
454(@code{mail-bcc}).
455@item C-c C-f C-f
456Move to the @samp{FCC} header field, creating one if there is none
457(@code{mail-fcc}).
458@item M-@key{TAB}
459Complete a mailing address (@code{mail-complete}).
460@end table
461
462@kindex C-c C-f C-t @r{(Mail mode)}
463@findex mail-to
464@kindex C-c C-f C-s @r{(Mail mode)}
465@findex mail-subject
466@kindex C-c C-f C-c @r{(Mail mode)}
467@findex mail-cc
468@kindex C-c C-f C-b @r{(Mail mode)}
469@findex mail-bcc
470@kindex C-c C-f C-f @r{(Mail mode)}
471@findex mail-fcc
472 There are five commands to move point to particular header fields, all
473based on the prefix @kbd{C-c C-f} (@samp{C-f} is for ``field''). They
474are listed in the table above. If the field in question does not exist,
475these commands create one. We provide special motion commands for these
476particular fields because they are the fields users most often want to
477edit.
478
479@findex mail-complete
480@kindex M-TAB @r{(Mail mode)}
481 While editing a header field that contains mailing addresses, such as
482@samp{To:}, @samp{CC:} and @samp{BCC:}, you can complete a mailing
483address by typing @kbd{M-@key{TAB}} (@code{mail-complete}). It inserts
484the full name corresponding to the address, if it can determine the full
485name. The variable @code{mail-complete-style} controls whether to insert
486the full name, and what style to use, as in @code{mail-from-style}
487(@pxref{Mail Headers}).
488
489 For completion purposes, the valid mailing addresses are taken to be
7fc1fe09 490the local users' names plus your personal mail aliases. You can
58fa012d 491specify additional sources of valid addresses; look at the customization
7fc1fe09
RS
492group @samp{mailalias} to see the options for this
493(@pxref{Customization Groups}).
6bf7aab6 494
7fc1fe09
RS
495 If you type @kbd{M-@key{TAB}} in the body of the message,
496@code{mail-complete} invokes @code{ispell-complete-word}, as in Text
497mode.
6bf7aab6
DL
498
499@node Citing Mail
500@subsection Citing Mail
501@cindex citing mail
502
503 Mail mode also has commands for yanking or @dfn{citing} all or part of
504a message that you are replying to. These commands are active only when
505you started sending a message using an Rmail command.
506
507@table @kbd
508@item C-c C-y
509Yank the selected message from Rmail (@code{mail-yank-original}).
510@item C-c C-r
511Yank the region from the Rmail buffer (@code{mail-yank-region}).
512@item C-c C-q
513Fill each paragraph cited from another message
514(@code{mail-fill-yanked-message}).
515@end table
516
517@kindex C-c C-y @r{(Mail mode)}
518@findex mail-yank-original
519 When mail sending is invoked from the Rmail mail reader using an Rmail
520command, @kbd{C-c C-y} can be used inside the mail buffer to insert
521the text of the message you are replying to. Normally it indents each line
522of that message three spaces and eliminates most header fields. A numeric
523argument specifies the number of spaces to indent. An argument of just
524@kbd{C-u} says not to indent at all and not to eliminate anything.
525@kbd{C-c C-y} always uses the current message from the Rmail buffer,
526so you can insert several old messages by selecting one in Rmail,
527switching to @samp{*mail*} and yanking it, then switching back to
528Rmail to select another.
529
530@vindex mail-yank-prefix
531 You can specify the text for @kbd{C-c C-y} to insert at the beginning
532of each line: set @code{mail-yank-prefix} to the desired string. (A
533value of @code{nil} means to use indentation; this is the default.)
534However, @kbd{C-u C-c C-y} never adds anything at the beginning of the
535inserted lines, regardless of the value of @code{mail-yank-prefix}.
536
537@kindex C-c C-r @r{(Mail mode)}
538@findex mail-yank-region
539 To yank just a part of an incoming message, set the region in Rmail to
540the part you want; then go to the @samp{*Mail*} message and type
541@kbd{C-c C-r} (@code{mail-yank-region}). Each line that is copied is
542indented or prefixed according to @code{mail-yank-prefix}.
543
544@kindex C-c C-q @r{(Mail mode)}
545@findex mail-fill-yanked-message
546 After using @kbd{C-c C-y} or @kbd{C-c C-r}, you can type @kbd{C-c C-q}
547(@code{mail-fill-yanked-message}) to fill the paragraphs of the yanked
548old message or messages. One use of @kbd{C-c C-q} fills all such
549paragraphs, each one individually. To fill a single paragraph of the
550quoted message, use @kbd{M-q}. If filling does not automatically
551handle the type of citation prefix you use, try setting the fill prefix
552explicitly. @xref{Filling}.
553
554@node Mail Mode Misc
555@subsection Mail Mode Miscellany
556
557@table @kbd
558@item C-c C-t
559Move to the beginning of the message body text (@code{mail-text}).
560@item C-c C-w
561Insert the file @file{~/.signature} at the end of the message text
562(@code{mail-signature}).
563@item C-c C-i @var{file} @key{RET}
564Insert the contents of @var{file} at the end of the outgoing message
565(@code{mail-attach-file}).
566@item M-x ispell-message
58fa012d 567Perform spelling correction on the message text, but not on citations from
6bf7aab6
DL
568other messages.
569@end table
570
571@kindex C-c C-t @r{(Mail mode)}
572@findex mail-text
573 @kbd{C-c C-t} (@code{mail-text}) moves point to just after the header
574separator line---that is, to the beginning of the message body text.
575
576@kindex C-c C-w @r{(Mail mode)}
577@findex mail-signature
578@vindex mail-signature
579 @kbd{C-c C-w} (@code{mail-signature}) adds a standard piece of text at
580the end of the message to say more about who you are. The text comes
581from the file @file{~/.signature} in your home directory. To insert
582your signature automatically, set the variable @code{mail-signature} to
58fa012d 583@code{t}; after that, starting a mail message automatically inserts the
6bf7aab6
DL
584contents of your @file{~/.signature} file. If you want to omit your
585signature from a particular message, delete it from the buffer before
586you send the message.
587
588 You can also set @code{mail-signature} to a string; then that string
589is inserted automatically as your signature when you start editing a
590message to send. If you set it to some other Lisp expression, the
591expression is evaluated each time, and its value (which should be a
592string) specifies the signature.
593
594@findex ispell-message
595 You can do spelling correction on the message text you have written
596with the command @kbd{M-x ispell-message}. If you have yanked an
597incoming message into the outgoing draft, this command skips what was
598yanked, but it checks the text that you yourself inserted. (It looks
599for indentation or @code{mail-yank-prefix} to distinguish the cited
600lines from your input.) @xref{Spelling}.
601
602@kindex C-c C-i @r{(Mail mode)}
603@findex mail-attach-file
604 To include a file in the outgoing message, you can use @kbd{C-x i},
605the usual command to insert a file in the current buffer. But it is
606often more convenient to use a special command, @kbd{C-c C-i}
607(@code{mail-attach-file}). This command inserts the file contents at
608the end of the buffer, after your signature if any, with a delimiter
609line that includes the file name.
610
611@vindex mail-mode-hook
612@vindex mail-setup-hook
613 Turning on Mail mode (which @kbd{C-x m} does automatically) runs the
614normal hooks @code{text-mode-hook} and @code{mail-mode-hook}.
615Initializing a new outgoing message runs the normal hook
616@code{mail-setup-hook}; if you want to add special fields to your mail
617header or make other changes to the appearance of the mail buffer, use
618that hook. @xref{Hooks}.
619
620 The main difference between these hooks is just when they are
621invoked. Whenever you type @kbd{M-x mail}, @code{mail-mode-hook} runs
622as soon as the @samp{*mail*} buffer is created. Then the
58fa012d 623@code{mail-setup} function inserts the default contents of the buffer.
6bf7aab6
DL
624After these default contents are inserted, @code{mail-setup-hook} runs.
625
2e2cdb68
RS
626@node Mail Amusements
627@section Mail Amusements
6bf7aab6
DL
628
629@findex spook
630@cindex NSA
631 @kbd{M-x spook} adds a line of randomly chosen keywords to an outgoing
632mail message. The keywords are chosen from a list of words that suggest
633you are discussing something subversive.
634
2394fd21
DL
635 The idea behind this feature is the suspicion that the
636NSA@footnote{The US National Security Agency.} snoops on
6bf7aab6
DL
637all electronic mail messages that contain keywords suggesting they might
638find them interesting. (The NSA says they don't, but that's what they
639@emph{would} say.) The idea is that if lots of people add suspicious
640words to their messages, the NSA will get so busy with spurious input
641that they will have to give up reading it all.
642
643 Here's how to insert spook keywords automatically whenever you start
644entering an outgoing message:
645
646@example
2e2cdb68 647(add-hook 'mail-setup-hook 'spook)
6bf7aab6
DL
648@end example
649
650 Whether or not this confuses the NSA, it at least amuses people.
651
58eca4a5 652@findex fortune-to-signature
58eca4a5 653@cindex fortune cookies
2e2cdb68 654 You can use the @code{fortune} program to put a ``fortune cookie''
7fc1fe09 655message into outgoing mail. To do this, add
2e2cdb68
RS
656@code{fortune-to-signature} to @code{mail-setup-hook}:
657
658@example
659(add-hook 'mail-setup-hook 'fortune-to-signature)
660@end example
58eca4a5 661
6bf7aab6
DL
662@node Mail Methods
663@section Mail-Composition Methods
664@cindex mail-composition methods
665
26064e9b
DL
666@cindex MH mail interface
667@cindex Message mode for sending mail
2e2cdb68
RS
668 In this chapter we have described the usual Emacs mode for editing
669and sending mail---Mail mode. Emacs has alternative facilities for
670editing and sending mail, including
26064e9b 671MH-E and Message mode, not documented in this manual.
7fc1fe09 672@xref{MH-E,,,mh-e, The Emacs Interface to MH}. @xref{Message,,,message,
26064e9b
DL
673Message Manual}. You can choose any of them as your preferred method.
674The commands @code{C-x m}, @code{C-x 4 m} and @code{C-x 5 m} use
58fa012d 675whichever agent you have specified, as do various other Emacs commands
26064e9b 676and facilities that send mail.
6bf7aab6
DL
677
678@vindex mail-user-agent
37ad3ca0 679 To specify your mail-composition method, customize the variable
6bf7aab6 680@code{mail-user-agent}. Currently legitimate values include
2e2cdb68 681@code{sendmail-user-agent} (Mail mode), @code{mh-e-user-agent},
37ad3ca0 682@code{message-user-agent} and @code{gnus-user-agent}.
6bf7aab6 683
2e2cdb68
RS
684 If you select a different mail-composition method, the information
685in this chapter about the @samp{*mail*} buffer and Mail mode does not
686apply; the other methods use a different format of text in a different
687buffer, and their commands are different as well.
6bf7aab6 688