(directory_files_internal): Don't expand directory.
[bpt/emacs.git] / man / sending.texi
CommitLineData
6bf7aab6 1@c This is part of the Emacs manual.
ac1888f5 2@c Copyright (C) 1985,86,87,93,94,95,97,2000,2001, 2003
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
54a05782
RS
60@vindex mail-default-directory
61 The variable @code{mail-default-directory} controls the default
62directory for mail buffers, and also says where to put their auto-save
63files.
64
2e2cdb68
RS
65@ignore
66@c Commented out because it is not user-oriented;
67@c it doesn't say how to do some job. -- rms.
c016c701
DL
68@cindex directory servers
69@cindex LDAP
70@cindex PH/QI
71@cindex names and addresses
72There is an interface to directory servers using various protocols such
73as LDAP or the CCSO white pages directory system (PH/QI), described in a
74separate manual. It may be useful for looking up names and addresses.
75@xref{Top,,EUDC, eudc, EUDC Manual}.
2e2cdb68 76@end ignore
c016c701 77
6bf7aab6
DL
78@menu
79* Format: Mail Format. Format of the mail being composed.
80* Headers: Mail Headers. Details of permitted mail header fields.
81* Aliases: Mail Aliases. Abbreviating and grouping mail addresses.
82* Mode: Mail Mode. Special commands for editing mail being composed.
2e2cdb68 83* Amuse: Mail Amusements. Distracting the NSA; adding fortune messages.
2394fd21 84* Methods: Mail Methods. Using alternative mail-composition methods.
ac1888f5 85* SMTP: Sending via SMTP. Sending mail via SMTP.
6bf7aab6
DL
86@end menu
87
88@node Mail Format
89@section The Format of the Mail Buffer
90
91 In addition to the @dfn{text} or @dfn{body}, a message has @dfn{header
92fields} which say who sent it, when, to whom, why, and so on. Some
93header fields, such as @samp{Date} and @samp{Sender}, are created
94automatically when you send the message. Others, such as the recipient
95names, must be specified by you in order to send the message properly.
96
97 Mail mode provides a few commands to help you edit some header fields,
98and some are preinitialized in the buffer automatically at times. You can
99insert and edit header fields using ordinary editing commands.
100
101 The line in the buffer that says
102
103@example
104--text follows this line--
105@end example
106
107@noindent
108is a special delimiter that separates the headers you have specified from
109the text. Whatever follows this line is the text of the message; the
110headers precede it. The delimiter line itself does not appear in the
111message actually sent. The text used for the delimiter line is controlled
112by the variable @code{mail-header-separator}.
113
114Here is an example of what the headers and text in the mail buffer
115might look like.
116
117@example
118To: gnu@@gnu.org
119CC: lungfish@@spam.org, byob@@spam.org
120Subject: The Emacs Manual
121--Text follows this line--
122Please ignore this message.
123@end example
124
125@node Mail Headers
126@section Mail Header Fields
127@cindex headers (of mail message)
128
129 A header field in the mail buffer starts with a field name at the
130beginning of a line, terminated by a colon. Upper and lower case are
131equivalent in field names (and in mailing addresses also). After the
132colon and optional whitespace comes the contents of the field.
133
134 You can use any name you like for a header field, but normally people
135use only standard field names with accepted meanings. Here is a table
136of fields commonly used in outgoing messages.
137
138@table @samp
139@item To
140This field contains the mailing addresses to which the message is
141addressed. If you list more than one address, use commas, not spaces,
142to separate them.
143
144@item Subject
145The contents of the @samp{Subject} field should be a piece of text
146that says what the message is about. The reason @samp{Subject} fields
147are useful is that most mail-reading programs can provide a summary of
148messages, listing the subject of each message but not its text.
149
150@item CC
151This field contains additional mailing addresses to send the message to,
152like @samp{To} except that these readers should not regard the message
153as directed at them.
154
155@item BCC
156This field contains additional mailing addresses to send the message to,
157which should not appear in the header of the message actually sent.
158Copies sent this way are called @dfn{blind carbon copies}.
159
160@vindex mail-self-blind
c7fa86d5 161@cindex copy of every outgoing message
6bf7aab6 162To send a blind carbon copy of every outgoing message to yourself, set
c7fa86d5
EZ
163the variable @code{mail-self-blind} to @code{t}. To send a blind carbon
164copy of every message to some other @var{address}, set the variable
2e2cdb68 165@code{mail-default-headers} to @code{"Bcc: @var{address}\n"}.
6bf7aab6
DL
166
167@item FCC
168This field contains the name of one file and directs Emacs to append a
169copy of the message to that file when you send the message. If the file
170is in Rmail format, Emacs writes the message in Rmail format; otherwise,
7fc1fe09
RS
171Emacs writes the message in system mail file format. To specify
172more than one file, use several @samp{FCC} fields, with one file
173name in each field.
6bf7aab6
DL
174
175@vindex mail-archive-file-name
176To put a fixed file name in the @samp{FCC} field each time you start
177editing an outgoing message, set the variable
178@code{mail-archive-file-name} to that file name. Unless you remove the
179@samp{FCC} field before sending, the message will be written into that
180file when it is sent.
181
182@item From
183Use the @samp{From} field to say who you are, when the account you are
184using to send the mail is not your own. The contents of the @samp{From}
185field should be a valid mailing address, since replies will normally go
186there. If you don't specify the @samp{From} field yourself, Emacs uses
187the value of @code{user-mail-address} as the default.
188
189@item Reply-to
190Use this field to direct replies to a different address. Most
191mail-reading programs (including Rmail) automatically send replies to
192the @samp{Reply-to} address in preference to the @samp{From} address.
193By adding a @samp{Reply-to} field to your header, you can work around
194any problems your @samp{From} address may cause for replies.
195
60a96371 196@cindex @env{REPLYTO} environment variable
6bf7aab6
DL
197@vindex mail-default-reply-to
198To put a fixed @samp{Reply-to} address into every outgoing message, set
199the variable @code{mail-default-reply-to} to that address (as a string).
200Then @code{mail} initializes the message with a @samp{Reply-to} field as
201specified. You can delete or alter that header field before you send
202the message, if you wish. When Emacs starts up, if the environment
60a96371 203variable @env{REPLYTO} is set, @code{mail-default-reply-to} is
6bf7aab6
DL
204initialized from that environment variable.
205
206@item In-reply-to
58fa012d 207This field contains a piece of text describing the message you are
6bf7aab6
DL
208replying to. Some mail systems can use this information to correlate
209related pieces of mail. Normally this field is filled in by Rmail
210when you reply to a message in Rmail, and you never need to
211think about it (@pxref{Rmail}).
212
213@item References
214This field lists the message IDs of related previous messages. Rmail
215sets up this field automatically when you reply to a message.
216@end table
217
7fc1fe09
RS
218 The @samp{To}, @samp{CC}, and @samp{BCC} header fields can appear
219any number of times, and each such header field can contain multiple
220addresses, separated by commas. This way, you can specify any number
221of places to send the message. These fields can also have
222continuation lines: one or more lines starting with whitespace,
223following the starting line of the field, are considered part of the
224field. Here's an example of a @samp{To} field with a continuation
225line:@refill
6bf7aab6
DL
226
227@example
228@group
229To: foo@@here.net, this@@there.net,
230 me@@gnu.cambridge.mass.usa.earth.spiral3281
231@end group
232@end example
233
234@vindex mail-from-style
235 When you send the message, if you didn't write a @samp{From} field
236yourself, Emacs puts in one for you. The variable
237@code{mail-from-style} controls the format:
238
239@table @code
240@item nil
241Use just the email address, as in @samp{king@@grassland.com}.
242@item parens
243Use both email address and full name, as in @samp{king@@grassland.com (Elvis
244Parsley)}.
245@item angles
246Use both email address and full name, as in @samp{Elvis Parsley
247<king@@grassland.com>}.
248@item system-default
249Allow the system to insert the @samp{From} field.
250@end table
251
c7fa86d5 252@vindex mail-default-headers
2e2cdb68
RS
253 You can direct Emacs to insert certain default headers into the
254outgoing message by setting the variable @code{mail-default-headers}
255to a string. Then @code{C-x m} inserts this string into the message
256headers. If the default header fields are not appropriate for a
257particular message, edit them as appropriate before sending the
258message.
c7fa86d5 259
6bf7aab6
DL
260@node Mail Aliases
261@section Mail Aliases
262@cindex mail aliases
263@cindex @file{.mailrc} file
264@cindex mailrc file
265
266 You can define @dfn{mail aliases} in a file named @file{~/.mailrc}.
267These are short mnemonic names which stand for mail addresses or groups of
268mail addresses. Like many other mail programs, Emacs expands aliases
269when they occur in the @samp{To}, @samp{From}, @samp{CC}, @samp{BCC}, and
270@samp{Reply-to} fields, plus their @samp{Resent-} variants.
271
272 To define an alias in @file{~/.mailrc}, write a line in the following
273format:
274
275@example
276alias @var{shortaddress} @var{fulladdresses}
277@end example
278
279@noindent
280Here @var{fulladdresses} stands for one or more mail addresses for
281@var{shortaddress} to expand into. Separate multiple addresses with
282spaces; if an address contains a space, quote the whole address with a
283pair of double-quotes.
284
285For instance, to make @code{maingnu} stand for
286@code{gnu@@gnu.org} plus a local address of your own, put in
287this line:@refill
288
289@example
290alias maingnu gnu@@gnu.org local-gnu
291@end example
292
293 Emacs also recognizes include commands in @samp{.mailrc} files.
294They look like this:
295
296@example
297source @var{filename}
298@end example
299
300@noindent
301The file @file{~/.mailrc} is used primarily by other mail-reading
302programs; it can contain various other commands. Emacs ignores
303everything in it except for alias definitions and include commands.
304
305@findex define-mail-alias
306 Another way to define a mail alias, within Emacs alone, is with the
307@code{define-mail-alias} command. It prompts for the alias and then the
308full address. You can use it to define aliases in your @file{.emacs}
309file, like this:
310
311@example
312(define-mail-alias "maingnu" "gnu@@gnu.org")
313@end example
314
315@vindex mail-aliases
316 @code{define-mail-alias} records aliases by adding them to a
317variable named @code{mail-aliases}. If you are comfortable with
318manipulating Lisp lists, you can set @code{mail-aliases} directly. The
319initial value of @code{mail-aliases} is @code{t}, which means that
320Emacs should read @file{.mailrc} to get the proper value.
321
322@vindex mail-personal-alias-file
323 You can specify a different file name to use instead of
324@file{~/.mailrc} by setting the variable
325@code{mail-personal-alias-file}.
326
327@findex expand-mail-aliases
328 Normally, Emacs expands aliases when you send the message. You do not
329need to expand mail aliases before sending the message, but you can
330expand them if you want to see where the mail will actually go. To do
331this, use the command @kbd{M-x expand-mail-aliases}; it expands all mail
332aliases currently present in the mail headers that hold addresses.
333
334 If you like, you can have mail aliases expand as abbrevs, as soon as
335you type them in (@pxref{Abbrevs}). To enable this feature, execute the
336following:
337
338@example
49172314 339(add-hook 'mail-mode-hook 'mail-abbrevs-setup)
6bf7aab6
DL
340@end example
341
342@noindent
343@findex define-mail-abbrev
344@vindex mail-abbrevs
345This can go in your @file{.emacs} file. @xref{Hooks}. If you use this
346feature, you must use @code{define-mail-abbrev} instead of
347@code{define-mail-alias}; the latter does not work with this package.
348Note that the mail abbreviation package uses the variable
349@code{mail-abbrevs} instead of @code{mail-aliases}, and that all alias
350names are converted to lower case.
351
352@kindex C-c C-a @r{(Mail mode)}
353@findex mail-interactive-insert-alias
354 The mail abbreviation package also provides the @kbd{C-c C-a}
355(@code{mail-interactive-insert-alias}) command, which reads an alias
356name (with completion) and inserts its definition at point. This is
357useful when editing the message text itself or a header field such as
358@samp{Subject} in which Emacs does not normally expand aliases.
359
360 Note that abbrevs expand only if you insert a word-separator character
361afterward. However, you can rebind @kbd{C-n} and @kbd{M->} to cause
362expansion as well. Here's how to do that:
363
364@smallexample
49172314 365(add-hook 'mail-mode-hook
43aef553
SM
366 (lambda ()
367 (substitute-key-definition
368 'next-line 'mail-abbrev-next-line
369 mail-mode-map global-map)
370 (substitute-key-definition
371 'end-of-buffer 'mail-abbrev-end-of-buffer
372 mail-mode-map global-map)))
6bf7aab6
DL
373@end smallexample
374
375@node Mail Mode
376@section Mail Mode
377@cindex Mail mode
378@cindex mode, Mail
379
380 The major mode used in the mail buffer is Mail mode, which is much
381like Text mode except that various special commands are provided on the
382@kbd{C-c} prefix. These commands all have to do specifically with
383editing or sending the message. In addition, Mail mode defines the
384character @samp{%} as a word separator; this is helpful for using the
385word commands to edit mail addresses.
386
387 Mail mode is normally used in buffers set up automatically by the
388@code{mail} command and related commands. However, you can also switch
58fa012d
EZ
389to Mail mode in a file-visiting buffer. This is a useful thing to do if
390you have saved the text of a draft message in a file.
6bf7aab6
DL
391
392@menu
393* Mail Sending:: Commands to send the message.
394* Header Editing:: Commands to move to header fields and edit them.
395* Citing Mail:: Copying all or part of a message you are replying to.
396* Mail Mode Misc:: Spell checking, signatures, etc.
397@end menu
398
399@node Mail Sending
400@subsection Mail Sending
401
402 Mail mode has two commands for sending the message you have been
403editing:
404
405@table @kbd
406@item C-c C-s
407Send the message, and leave the mail buffer selected (@code{mail-send}).
408@item C-c C-c
409Send the message, and select some other buffer (@code{mail-send-and-exit}).
410@end table
411
412@kindex C-c C-s @r{(Mail mode)}
413@kindex C-c C-c @r{(Mail mode)}
414@findex mail-send
415@findex mail-send-and-exit
416 @kbd{C-c C-s} (@code{mail-send}) sends the message and marks the mail
417buffer unmodified, but leaves that buffer selected so that you can
418modify the message (perhaps with new recipients) and send it again.
419@kbd{C-c C-c} (@code{mail-send-and-exit}) sends and then deletes the
420window or switches to another buffer. It puts the mail buffer at the
421lowest priority for reselection by default, since you are finished with
422using it. This is the usual way to send the message.
423
424 In a file-visiting buffer, sending the message does not clear the
425modified flag, because only saving the file should do that. As a
426result, you don't get a warning if you try to send the same message
427twice.
428
4946337d
EZ
429@c This is indexed in mule.texi, node "Recognize Coding".
430@c @vindex sendmail-coding-system
6bf7aab6
DL
431 When you send a message that contains non-ASCII characters, they need
432to be encoded with a coding system (@pxref{Coding Systems}). Usually
433the coding system is specified automatically by your chosen language
434environment (@pxref{Language Environments}). You can explicitly specify
435the coding system for outgoing mail by setting the variable
4946337d 436@code{sendmail-coding-system} (@pxref{Recognize Coding}).
6bf7aab6
DL
437
438 If the coding system thus determined does not handle the characters in
439a particular message, Emacs asks you to select the coding system to use,
440showing a list of possible coding systems.
441
442@node Header Editing
443@subsection Mail Header Editing
444
445 Mail mode provides special commands to move to particular header
446fields and to complete addresses in headers.
447
448@table @kbd
449@item C-c C-f C-t
450Move to the @samp{To} header field, creating one if there is none
451(@code{mail-to}).
452@item C-c C-f C-s
453Move to the @samp{Subject} header field, creating one if there is
454none (@code{mail-subject}).
455@item C-c C-f C-c
456Move to the @samp{CC} header field, creating one if there is none
457(@code{mail-cc}).
458@item C-c C-f C-b
459Move to the @samp{BCC} header field, creating one if there is none
460(@code{mail-bcc}).
461@item C-c C-f C-f
462Move to the @samp{FCC} header field, creating one if there is none
463(@code{mail-fcc}).
464@item M-@key{TAB}
465Complete a mailing address (@code{mail-complete}).
466@end table
467
468@kindex C-c C-f C-t @r{(Mail mode)}
469@findex mail-to
470@kindex C-c C-f C-s @r{(Mail mode)}
471@findex mail-subject
472@kindex C-c C-f C-c @r{(Mail mode)}
473@findex mail-cc
474@kindex C-c C-f C-b @r{(Mail mode)}
475@findex mail-bcc
476@kindex C-c C-f C-f @r{(Mail mode)}
477@findex mail-fcc
478 There are five commands to move point to particular header fields, all
479based on the prefix @kbd{C-c C-f} (@samp{C-f} is for ``field''). They
480are listed in the table above. If the field in question does not exist,
481these commands create one. We provide special motion commands for these
482particular fields because they are the fields users most often want to
483edit.
484
485@findex mail-complete
486@kindex M-TAB @r{(Mail mode)}
487 While editing a header field that contains mailing addresses, such as
488@samp{To:}, @samp{CC:} and @samp{BCC:}, you can complete a mailing
489address by typing @kbd{M-@key{TAB}} (@code{mail-complete}). It inserts
490the full name corresponding to the address, if it can determine the full
491name. The variable @code{mail-complete-style} controls whether to insert
492the full name, and what style to use, as in @code{mail-from-style}
493(@pxref{Mail Headers}).
494
495 For completion purposes, the valid mailing addresses are taken to be
7fc1fe09 496the local users' names plus your personal mail aliases. You can
58fa012d 497specify additional sources of valid addresses; look at the customization
7fc1fe09
RS
498group @samp{mailalias} to see the options for this
499(@pxref{Customization Groups}).
6bf7aab6 500
7fc1fe09
RS
501 If you type @kbd{M-@key{TAB}} in the body of the message,
502@code{mail-complete} invokes @code{ispell-complete-word}, as in Text
503mode.
6bf7aab6
DL
504
505@node Citing Mail
506@subsection Citing Mail
507@cindex citing mail
508
509 Mail mode also has commands for yanking or @dfn{citing} all or part of
510a message that you are replying to. These commands are active only when
511you started sending a message using an Rmail command.
512
513@table @kbd
514@item C-c C-y
515Yank the selected message from Rmail (@code{mail-yank-original}).
516@item C-c C-r
517Yank the region from the Rmail buffer (@code{mail-yank-region}).
518@item C-c C-q
519Fill each paragraph cited from another message
520(@code{mail-fill-yanked-message}).
521@end table
522
523@kindex C-c C-y @r{(Mail mode)}
524@findex mail-yank-original
525 When mail sending is invoked from the Rmail mail reader using an Rmail
526command, @kbd{C-c C-y} can be used inside the mail buffer to insert
527the text of the message you are replying to. Normally it indents each line
528of that message three spaces and eliminates most header fields. A numeric
529argument specifies the number of spaces to indent. An argument of just
530@kbd{C-u} says not to indent at all and not to eliminate anything.
531@kbd{C-c C-y} always uses the current message from the Rmail buffer,
532so you can insert several old messages by selecting one in Rmail,
533switching to @samp{*mail*} and yanking it, then switching back to
534Rmail to select another.
535
536@vindex mail-yank-prefix
537 You can specify the text for @kbd{C-c C-y} to insert at the beginning
538of each line: set @code{mail-yank-prefix} to the desired string. (A
539value of @code{nil} means to use indentation; this is the default.)
540However, @kbd{C-u C-c C-y} never adds anything at the beginning of the
541inserted lines, regardless of the value of @code{mail-yank-prefix}.
542
543@kindex C-c C-r @r{(Mail mode)}
544@findex mail-yank-region
545 To yank just a part of an incoming message, set the region in Rmail to
546the part you want; then go to the @samp{*Mail*} message and type
547@kbd{C-c C-r} (@code{mail-yank-region}). Each line that is copied is
548indented or prefixed according to @code{mail-yank-prefix}.
549
550@kindex C-c C-q @r{(Mail mode)}
551@findex mail-fill-yanked-message
552 After using @kbd{C-c C-y} or @kbd{C-c C-r}, you can type @kbd{C-c C-q}
553(@code{mail-fill-yanked-message}) to fill the paragraphs of the yanked
554old message or messages. One use of @kbd{C-c C-q} fills all such
555paragraphs, each one individually. To fill a single paragraph of the
556quoted message, use @kbd{M-q}. If filling does not automatically
557handle the type of citation prefix you use, try setting the fill prefix
558explicitly. @xref{Filling}.
559
560@node Mail Mode Misc
561@subsection Mail Mode Miscellany
562
563@table @kbd
564@item C-c C-t
565Move to the beginning of the message body text (@code{mail-text}).
566@item C-c C-w
567Insert the file @file{~/.signature} at the end of the message text
568(@code{mail-signature}).
569@item C-c C-i @var{file} @key{RET}
570Insert the contents of @var{file} at the end of the outgoing message
571(@code{mail-attach-file}).
572@item M-x ispell-message
58fa012d 573Perform spelling correction on the message text, but not on citations from
6bf7aab6
DL
574other messages.
575@end table
576
577@kindex C-c C-t @r{(Mail mode)}
578@findex mail-text
579 @kbd{C-c C-t} (@code{mail-text}) moves point to just after the header
580separator line---that is, to the beginning of the message body text.
581
582@kindex C-c C-w @r{(Mail mode)}
583@findex mail-signature
584@vindex mail-signature
585 @kbd{C-c C-w} (@code{mail-signature}) adds a standard piece of text at
586the end of the message to say more about who you are. The text comes
587from the file @file{~/.signature} in your home directory. To insert
588your signature automatically, set the variable @code{mail-signature} to
58fa012d 589@code{t}; after that, starting a mail message automatically inserts the
6bf7aab6
DL
590contents of your @file{~/.signature} file. If you want to omit your
591signature from a particular message, delete it from the buffer before
592you send the message.
593
594 You can also set @code{mail-signature} to a string; then that string
595is inserted automatically as your signature when you start editing a
596message to send. If you set it to some other Lisp expression, the
597expression is evaluated each time, and its value (which should be a
598string) specifies the signature.
599
600@findex ispell-message
601 You can do spelling correction on the message text you have written
602with the command @kbd{M-x ispell-message}. If you have yanked an
603incoming message into the outgoing draft, this command skips what was
604yanked, but it checks the text that you yourself inserted. (It looks
605for indentation or @code{mail-yank-prefix} to distinguish the cited
606lines from your input.) @xref{Spelling}.
607
608@kindex C-c C-i @r{(Mail mode)}
609@findex mail-attach-file
610 To include a file in the outgoing message, you can use @kbd{C-x i},
611the usual command to insert a file in the current buffer. But it is
612often more convenient to use a special command, @kbd{C-c C-i}
613(@code{mail-attach-file}). This command inserts the file contents at
614the end of the buffer, after your signature if any, with a delimiter
615line that includes the file name.
616
617@vindex mail-mode-hook
618@vindex mail-setup-hook
619 Turning on Mail mode (which @kbd{C-x m} does automatically) runs the
620normal hooks @code{text-mode-hook} and @code{mail-mode-hook}.
621Initializing a new outgoing message runs the normal hook
622@code{mail-setup-hook}; if you want to add special fields to your mail
623header or make other changes to the appearance of the mail buffer, use
624that hook. @xref{Hooks}.
625
626 The main difference between these hooks is just when they are
627invoked. Whenever you type @kbd{M-x mail}, @code{mail-mode-hook} runs
628as soon as the @samp{*mail*} buffer is created. Then the
58fa012d 629@code{mail-setup} function inserts the default contents of the buffer.
6bf7aab6
DL
630After these default contents are inserted, @code{mail-setup-hook} runs.
631
2e2cdb68
RS
632@node Mail Amusements
633@section Mail Amusements
6bf7aab6
DL
634
635@findex spook
636@cindex NSA
637 @kbd{M-x spook} adds a line of randomly chosen keywords to an outgoing
638mail message. The keywords are chosen from a list of words that suggest
639you are discussing something subversive.
640
2394fd21
DL
641 The idea behind this feature is the suspicion that the
642NSA@footnote{The US National Security Agency.} snoops on
6bf7aab6
DL
643all electronic mail messages that contain keywords suggesting they might
644find them interesting. (The NSA says they don't, but that's what they
645@emph{would} say.) The idea is that if lots of people add suspicious
646words to their messages, the NSA will get so busy with spurious input
647that they will have to give up reading it all.
648
649 Here's how to insert spook keywords automatically whenever you start
650entering an outgoing message:
651
652@example
2e2cdb68 653(add-hook 'mail-setup-hook 'spook)
6bf7aab6
DL
654@end example
655
656 Whether or not this confuses the NSA, it at least amuses people.
657
58eca4a5 658@findex fortune-to-signature
58eca4a5 659@cindex fortune cookies
2e2cdb68 660 You can use the @code{fortune} program to put a ``fortune cookie''
7fc1fe09 661message into outgoing mail. To do this, add
2e2cdb68
RS
662@code{fortune-to-signature} to @code{mail-setup-hook}:
663
664@example
665(add-hook 'mail-setup-hook 'fortune-to-signature)
666@end example
58eca4a5 667
6bf7aab6
DL
668@node Mail Methods
669@section Mail-Composition Methods
670@cindex mail-composition methods
671
26064e9b
DL
672@cindex MH mail interface
673@cindex Message mode for sending mail
2e2cdb68
RS
674 In this chapter we have described the usual Emacs mode for editing
675and sending mail---Mail mode. Emacs has alternative facilities for
676editing and sending mail, including
26064e9b 677MH-E and Message mode, not documented in this manual.
7fc1fe09 678@xref{MH-E,,,mh-e, The Emacs Interface to MH}. @xref{Message,,,message,
26064e9b
DL
679Message Manual}. You can choose any of them as your preferred method.
680The commands @code{C-x m}, @code{C-x 4 m} and @code{C-x 5 m} use
58fa012d 681whichever agent you have specified, as do various other Emacs commands
26064e9b 682and facilities that send mail.
6bf7aab6
DL
683
684@vindex mail-user-agent
37ad3ca0 685 To specify your mail-composition method, customize the variable
6bf7aab6 686@code{mail-user-agent}. Currently legitimate values include
2e2cdb68 687@code{sendmail-user-agent} (Mail mode), @code{mh-e-user-agent},
37ad3ca0 688@code{message-user-agent} and @code{gnus-user-agent}.
6bf7aab6 689
2e2cdb68
RS
690 If you select a different mail-composition method, the information
691in this chapter about the @samp{*mail*} buffer and Mail mode does not
692apply; the other methods use a different format of text in a different
693buffer, and their commands are different as well.
6bf7aab6 694
ac1888f5
SJ
695@node Sending via SMTP
696@section Sending via SMTP
697@cindex SMTP
698
3b41b693
SJ
699 On the Internet, mail is sent from host to host using the simple
700mail transfer protocol (SMTP). When you read and write mail you are
701using a mail program that does not use SMTP -- it just reads mails
702from files. This is called a mail user agent (MUA). The mail
703transfer agent (MTA) is the program that accepts mails via SMTP and
704stores them in files. You also need a mail transfer agent when you
705send mails. Your mail program has to send its mail to a MTA that can
706pass it on using SMTP.
707
708 Emacs includes a package for sending your mail to a SMTP server and
ac1888f5
SJ
709have it take care of delivering it to the final destination, rather
710than letting the MTA on your local system take care of it. This can
711be useful if you don't have a MTA set up on your host, or if your
712machine is often disconnected from the Internet.
713
714 Sending mail via SMTP requires configuring your mail user agent
715(@pxref{Mail Methods}) to use the SMTP library. How to do this should
716be described for each mail user agent; for the Message and Gnus user
717agents the variable @code{message-send-mail-function} (@pxref{Mail
718Variables,,,message}) is used.
719
720@vindex send-mail-function
721 The variable @code{send-mail-function} controls how the default mail
722user agent sends mail. It should be set to a function. The default
723is @code{sendmail-send-it}, but must be set to @code{smtpmail-send-it}
724in order to use the SMTP library. @code{feedmail-send-it} is another
725option.
726
727 Before using SMTP you must find out the hostname of the SMTP server
728to use. Your system administrator should provide you with this
729information, but often it is the same as the server you receive mail
730from.
731
732@vindex smtpmail-smtp-server
733 The variable @code{smtpmail-smtp-server} controls the hostname of
734the server to use. It is a string with an IP address or hostname. It
735defaults to the contents of the @code{SMTPSERVER} environment
736variable, or, if empty, the contents of
737@code{smtpmail-default-smtp-server}.
738
739@vindex smtpmail-default-smtp-server
740 The variable @code{smtpmail-default-smtp-server} controls the
741default hostname of the server to use. It is a string with an IP
742address or hostname. It must be set before the SMTP library is
743loaded. It has no effect if set after the SMTP library has been
744loaded, or if @code{smtpmail-smtp-server} is defined. It is usually
745set by system administrators in a site wide initialization file.
746
747@cindex Mail Submission
748SMTP is normally used on the registered ``smtp'' TCP service port 25.
749Some environments use SMTP in ``Mail Submission'' mode, which uses
750port 587. Using other ports is not uncommon, either for security by
751obscurity purposes, port forwarding, or otherwise.
752
753@vindex smtpmail-smtp-service
754 The variable @code{smtpmail-smtp-service} controls the port on the
755server to contact. It is either a string, in which case it will be
756translated into an integer using system calls, or an integer.
757
758Many environments require SMTP clients to authenticate themselves
759before they are allowed to route mail via a server. The two following
760variables contains the authentication information needed for this.
761The first variable, @code{smtpmail-auth-credentials}, instructs the
762SMTP library to use a SASL authentication step, currently only the
763CRAM-MD5, PLAIN and LOGIN-MD5 mechanisms are supported and will be
764selected in that order if the server supports them. The second
765variable, @code{smtpmail-starttls-credentials}, instructs the SMTP
766library to connect to the server using STARTTLS. This means the
767protocol exchange can be integrity protected and confidential by using
768TLS, and optionally also authentication of the client. It is common
769to use both these mechanisms, e.g. to use STARTTLS to achieve
770integrity and confidentiality and then use SASL for client
771authentication.
772
773@vindex smtpmail-auth-credentials
774 The variable @code{smtpmail-auth-credentials} contains a list of
775hostname, port, username and password tuples. When the SMTP library
776connects to a host on a certain port, this variable is searched to
777find a matching entry for that hostname and port. If an entry is
778found, the authentication process is invoked and the credentials are
779used. The hostname field follows the same format as
780@code{smtpmail-smtp-server} (i.e., a string) and the port field the
781same format as @code{smtpmail-smtp-service} (i.e., a string or an
782integer). The username and password fields, which either can be
783@samp{nil} to indicate that the user is queried for the value
784interactively, should be strings with the username and password,
785respectively, information that is normally provided by system
786administrators.
787
788@vindex smtpmail-starttls-credentials
789 The variable @code{smtpmail-starttls-credentials} contains a list of
790tuples with hostname, port, name of file containing client key, and
791name of file containing client certificate. The processing is similar
792to the previous variable. The client key and certificate may be
793@samp{nil} if you do not wish to use client authentication. The use
794of this variable requires the @samp{starttls} external program to be
795installed, you can get it from
796@samp{ftp://ftp.opaopa.org/pub/elisp/starttls-*.tar.gz}.
797
798The remaining variables are more esoteric and is normally not needed.
799
800@vindex smtpmail-debug-info
801 The variable @code{smtpmail-debug-info} controls whether to print
802the SMTP protocol exchange in the minibuffer, and retain the entire
803exchange in a buffer @samp{*trace of SMTP session to
804mail.example.org*}.
805
806@vindex smtpmail-debug-verb
807 The variable @code{smtpmail-debug-verb} controls whether to send the
808VERB token to the server. The VERB server instructs the server to be
809more verbose, and often also to attempt final delivery while your SMTP
810session is still running. It is usually only useful together with
811@code{smtpmail-debug-info}. Note that this may cause mail delivery to
812take considerable time if the final destination cannot accept mail.
813
814@vindex smtpmail-local-domain
815 The variable @code{smtpmail-local-domain} controls the hostname sent
816in the first EHLO or HELO command sent to the server. It should only
817be set if the @code{system-name} function returns a name that isn't
818accepted by the server. Do not set this variable unless your server
819complains.
820
821@vindex smtpmail-sendto-domain
822 The variable @code{smtpmail-sendto-domain} makes the SMTP library
823add @samp{@@} and the specified value to recipients specified in the
824message when they are sent using the RCPT TO command. Some
825configurations of sendmail requires this behaviour. Don't bother to
826set this unless you have get an error like:
827
828@example
829 Sending failed; SMTP protocol error
830@end example
831
832when sending mail, and the *trace of SMTP session to <somewhere>*
833buffer (enabled via @code{smtpmail-debug-info}) includes an exchange
834like:
835
836@example
837 RCPT TO: <someone>
838 501 <someone>: recipient address must contain a domain
839@end example
840
841@vindex smtpmail-queue-mail
842 The variable @code{smtpmail-queue-mail} controls whether a simple
843off line mail sender is active. This variable is a boolean, and
844defaults to @samp{nil} (disabled). If this is non-nil, mail is not
845sent immediately but rather queued in the directory
846@code{smtpmail-queue-dir} and can be later sent manually by invoking
847@code{smtpmail-send-queued-mail} (typically when you connect to the
848Internet).
849
850@vindex smtpmail-queue-dir
851 The variable @code{smtpmail-queue-dir} specifies the name of the
852directory to hold queued messages. It defaults to
853@samp{~/Mail/queued-mail/}.
854
855@findex smtpmail-send-queued-mail
856 The function @code{smtpmail-send-queued-mail} can be used to send
857any queued mail when @code{smtpmail-queue-mail} is enabled. It is
858typically invoked interactively with @kbd{M-x RET
859smtpmail-send-queued-mail RET} when you are connected to the Internet.