1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985-1987, 1993-1995, 1997, 2000-2011
3 @c Free Software Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
14 To send an email message from Emacs, type @kbd{C-x m}. This
15 switches to a buffer named @samp{*unsent mail*}, where you can edit
16 the text and headers of the message. When done, type @kbd{C-c C-s} or
17 @kbd{C-c C-c} to send it.
21 Begin composing mail (@code{compose-mail}).
23 Likewise, in another window (@code{compose-mail-other-window}).
25 Likewise, but in a new frame (@code{compose-mail-other-frame}).
27 In the mail buffer, send the message (@code{message-send}).
29 In the mail buffer, send the message and bury the buffer
30 (@code{message-send-and-exit}).
33 The mail buffer is an ordinary Emacs buffer, so you can switch to
34 other buffers while composing the mail. If you want to send another
35 mail before finishing the current one, type @kbd{C-x m} again to open
36 a new mail buffer whose name has a different numeric suffix
37 (@pxref{Misc Buffer}). If you invoke the command with a prefix
38 argument, @w{@kbd{C-u C-x m}}, Emacs switches back to the last mail
39 buffer, and asks if you want to erase the message in that buffer; if
40 you answer no, this lets you pick up editing the message where you
44 @findex compose-mail-other-window
46 @findex compose-mail-other-frame
47 The command @kbd{C-x 4 m} (@code{compose-mail-other-window}) does
48 the same as @kbd{C-x m}, except it displays the mail buffer in a
49 different window. The command @kbd{C-x 5 m}
50 (@code{compose-mail-other-frame}) does it in a new frame.
52 When you type @kbd{C-c C-c} or @kbd{C-c C-s} to send the mail, Emacs
53 may ask you how it should deliver the mail---either directly via SMTP,
54 or using some other method. @xref{Mail Sending}, for details.
57 * Format: Mail Format. Format of a mail message.
58 * Headers: Mail Headers. Details of some standard mail header fields.
59 * Aliases: Mail Aliases. Abbreviating and grouping mail addresses.
60 * Commands: Mail Commands. Special commands for editing mail being composed.
61 * Signature: Mail Signature. Adding a signature to every message.
62 * Amuse: Mail Amusements. Distracting the NSA; adding fortune messages.
63 * Methods: Mail Methods. Using alternative mail-composition methods.
67 @section The Format of the Mail Buffer
69 Here is an example of the contents of a mail buffer:
72 To: subotai@@example.org
73 CC: mongol.soldier@@example.net, rms@@gnu.org
74 Subject: Re: What is best in life?
75 From: conan@@example.org
76 --text follows this line--
77 To crush your enemies, see them driven before you, and to hear the
78 lamentation of their women.
82 At the top of the mail buffer is a set of @dfn{header fields}, which
83 are used for specifying information about the email's recipient(s),
84 subject, and so on. The above buffer contains header fields for
85 @samp{To}, @samp{Cc}, @samp{Subject}, and @samp{From}. Some header
86 fields are automatically pre-initialized in the mail buffer, when
89 The line that says @samp{--text follows this line--} separates the
90 header fields from the @dfn{body} (or @dfn{text}) of the message.
91 Everything above that line is treated as part of the headers;
92 everything below it is treated as the body. The delimiter line itself
93 does not appear in the message actually sent.
95 You can insert and edit header fields using ordinary editing
96 commands. @xref{Header Editing}, for commands specific to editing
97 header fields. Certain headers, such as @samp{Date} and
98 @samp{Message-Id}, are normally omitted from the mail buffer and are
99 created automatically when the message is sent.
102 @section Mail Header Fields
103 @cindex headers (of mail message)
105 A header field in the mail buffer starts with a field name at the
106 beginning of a line, terminated by a colon. Upper and lower case are
107 equivalent in field names. After the colon and optional whitespace
108 comes the contents of the field.
110 You can use any name you like for a header field, but normally
111 people use only standard field names with accepted meanings.
113 @vindex user-full-name
114 @vindex user-mail-address
115 The @samp{From} header field identifies the person sending the email
116 (i.e.@: you). This should be a valid mailing address, as replies are
117 normally sent there. The default contents of this header field are
118 computed from the variables @code{user-full-name} (which specifies
119 your full name) and @code{user-mail-address} (your email address). On
120 some operating systems, Emacs initializes these two variables using
121 environment variables (@pxref{General Variables}). If this
122 information is unavailable or wrong, you should customize the
123 variables yourself (@pxref{Easy Customization}).
125 @vindex mail-from-style
126 The value of the variable @code{mail-from-style} specifies how to
127 format the contents of the @samp{From} field:
131 Use just the address, as in @samp{king@@grassland.com}.
133 Use both address and full name, as in:@*
134 @samp{king@@grassland.com (Elvis Parsley)}.
136 Use both address and full name, as in:@*
137 @samp{Elvis Parsley <king@@grassland.com>}.
138 @item any other value
139 Use @code{angles} normally. But if the address must be ``quoted'' to
140 remain syntactically valid under the @code{angles} format but not
141 under the @code{parens} format, use @code{parens} instead. This is
145 Apart from @samp{From}, here is a table of commonly-used fields:
149 The mailing address(es) to which the message is addressed. To list
150 more than one address, use commas to separate them.
153 The subject of the message.
156 Additional mailing address(es) to send the message to. This is like
157 @samp{To}, except that these readers should not regard the message as
161 Additional mailing address(es) to send the message to, which should
162 not appear in the header of the message actually sent. ``BCC'' stands
163 for @dfn{blind carbon copies}.
166 The name of a file, to which a copy of the sent message should be
167 appended. Emacs writes the message in mbox format, unless the file is
168 in Babyl format (used by Rmail before Emacs 23), in which case Emacs
169 writes in Babyl format. If an Rmail buffer is visiting the file,
170 Emacs updates it accordingly. To specify more than one file, use
171 several @samp{FCC} fields, with one file name in each field.
174 An address to which replies should be sent, instead of @samp{From}.
175 This is used if, for some reason, your @samp{From} address cannot
179 This field takes precedence over @samp{Reply-to}. It is used because
180 some mailing lists set the @samp{Reply-to} field for their own
181 purposes (a somewhat controversial practice).
183 @item Mail-followup-to
184 One of more address(es) to use as default recipient(s) for follow-up
185 messages. This is typically used when you reply to a message from a
186 mailing list that you are subscribed to, and want replies to go to the
187 list without sending an extra copy to you.
190 An identifier for the message you are replying to. Most mail readers
191 use this information to group related messages together. Normally,
192 this header is filled in automatically when you reply to a message in
193 any mail program built into Emacs.
196 Identifiers for previous related messages. Like @samp{In-reply-to},
197 this is normally filled in automatically for you.
201 The @samp{To}, @samp{CC}, and @samp{BCC} fields can appear any number
202 of times, and each such header field can contain multiple addresses,
203 separated by commas. This way, you can specify any number of places
204 to send the message. These fields can also have continuation lines:
205 one or more lines starting with whitespace, following the starting
206 line of the field, are considered part of the field. Here's an
207 example of a @samp{To} field with a continuation line:
211 To: foo@@example.net, this@@example.net,
216 @c There is also mail-specify-envelope-from and mail-envelope-from, but
217 @c these are probably not topics for the Emacs manual.
219 @vindex mail-default-headers
220 You can direct Emacs to insert certain default headers into the mail
221 buffer by setting the variable @code{mail-default-headers} to a
222 string. Then @kbd{C-x m} inserts this string into the message
223 headers. For example, here is how to add a @samp{Reply-to} and
224 @samp{FCC} header to each message:
227 (setq mail-default-headers
228 "Reply-to: foo@@example.com\nFCC: ~/Mail/sent")
232 If the default header fields are not appropriate for a
233 particular message, edit them as necessary before sending the message.
236 @section Mail Aliases
238 @cindex @file{.mailrc} file
240 @vindex mail-personal-alias-file
242 You can define @dfn{mail aliases}, which are short mnemonic names
243 that stand for one or more mailing addresses. By default, mail
244 aliases are defined in the file @file{~/.mailrc}. You can specify a
245 different file name to use, by setting the variable
246 @code{mail-personal-alias-file}.
248 To define an alias in @file{.mailrc}, write a line like this:
251 alias @var{nick} @var{fulladdresses}
255 This means that @var{nick} should expand into @var{fulladdresses},
256 where @var{fulladdresses} can be either a single address, or multiple
257 addresses separated with spaces. For instance, to make @code{maingnu}
258 stand for @code{gnu@@gnu.org} plus a local address of your own, put in
262 alias maingnu gnu@@gnu.org local-gnu
266 If an address contains a space, quote the whole address with a pair of
267 double quotes, like this:
270 alias jsmith "John Q. Smith <none@@example.com>"
274 Note that you need not include double quotes around individual parts
275 of the address, such as the person's full name. Emacs puts them in if
276 they are needed. For instance, it inserts the above address as
277 @samp{"John Q. Smith" <none@@example.com>}.
279 Emacs also recognizes ``include'' commands in @file{.mailrc}. They
283 source @var{filename}
287 The @file{.mailrc} file is not unique to Emacs; many other
288 mail-reading programs use it for mail aliases, and it can contain
289 various other commands. However, Emacs ignores everything except
290 alias definitions and include commands.
292 @findex mail-abbrev-insert-alias
293 Mail aliases expand as abbrevs---that is to say, as soon as you type
294 a word-separator character after an alias (@pxref{Abbrevs}). This
295 expansion takes place only within the @samp{To}, @samp{From},
296 @samp{CC}, @samp{BCC}, and @samp{Reply-to} header fields (plus their
297 @samp{Resent-} variants); it does not take place in other header
298 fields, such as @samp{Subject}.
300 You can also insert an aliased address directly, using the command
301 @kbd{M-x mail-abbrev-insert-alias}. This reads an alias name, with
302 completion, and inserts its definition at point.
305 @section Mail Commands
307 @cindex mode, Message
309 The default major mode for the @samp{*mail*} buffer is called
310 Message mode. It behaves like Text mode in many ways, but provides
311 several additional commands on the @kbd{C-c} prefix, which make
312 editing a message more convenient.
314 In this section, we will describe some of the most commonly-used
315 commands available in Message mode.
317 Message mode also has its own manual, where its features are described
318 in greater detail. @xref{Top,,Message, message, Message}.
322 * Mail Sending:: Commands to send the message.
323 * Header Editing:: Commands to move to header fields and edit them.
324 * Citing Mail:: Quoting a message you are replying to.
325 * Mail Misc:: Attachments, spell checking, etc.
329 @subsection Mail Sending
331 There are two commands to send a message you have been editing:
335 Send the message, and deselect the mail buffer (@code{message-send-and-exit}).
337 Send the message, and leave the mail buffer selected (@code{message-send}).
340 @kindex C-c C-s @r{(Message mode)}
341 @kindex C-c C-c @r{(Message mode)}
343 If you want to send a message and be done with it, type @kbd{C-c
344 C-c} (@code{mail-send-and-exit}). This sends the message and then
345 either deletes the window or switches to another buffer. It also
346 ``buries'' the mail buffer, putting it at the lowest priority for
347 reselection. This is the usual command for sending a message.
349 @findex message-send-and-exit
350 The command @kbd{C-c C-s} (@code{message-send}) sends the message
351 and marks the mail buffer unmodified, but leaves the buffer selected.
352 Use this command if you want to modify the message (perhaps with new
353 recipients) and send it again.
355 @vindex message-send-hook
356 Sending a message runs the hook @code{message-send-hook}.
358 In a file-visiting buffer, sending the message does not clear the
359 modified flag, because only saving the file should do that. Also, you
360 don't get a warning if you try to send the same message twice.
362 @vindex sendmail-coding-system
363 When you send a message containing non-@acronym{ASCII} characters,
364 they need to be encoded with a coding system (@pxref{Coding Systems}).
365 Usually the coding system is specified automatically by your chosen
366 language environment (@pxref{Language Environments}). You can
367 explicitly specify the coding system for outgoing mail by setting the
368 variable @code{sendmail-coding-system} (@pxref{Recognize Coding}). If
369 the coding system thus determined does not handle the characters in a
370 particular message, Emacs asks you to select the coding system to use,
371 showing a list of possible coding systems.
377 @vindex send-mail-function
378 The variable @code{send-mail-function} controls how the message is
379 delivered. Its value should be a function, which can be one of the
383 @item sendmail-query-once
384 This function queries for a delivery method (one of the other entries
385 in this list), and uses that method for this message. Then it saves
386 the method to @code{send-mail-function}, so that the method is used
387 for future deliveries. This is the default, unless you have already
388 configured the @code{smtpmail-send-it} method.
390 @item smtpmail-send-it
391 Send mail through an external mail host, such as your Internet service
392 provider's outgoing SMTP mail server. If you have not told Emacs how
393 to contact the SMTP server, it prompts for this information (which is
394 saved in the variables @code{smtpmail-smtp-server} and
395 @code{smtpmail-auth-credentials}). @xref{Top,,Emacs SMTP Library,
396 smtpmail, Sending mail via SMTP}.
398 @item sendmail-send-it
399 Send mail using the system's default @command{sendmail} program, or
400 equivalent. This requires the system to be set up for delivering mail
403 @item mailclient-send-it
404 Pass the mail buffer on to the system's designated mail client. See
405 the commentary section in the file @file{mailclient.el} for details.
407 @item feedmail-send-it
408 This is similar to @code{sendmail-send-it}, but allows you to queue
409 messages for later sending. See the commentary section in the file
410 @file{feedmail.el} for details.
414 @subsection Mail Header Editing
416 Message mode provides the following special commands to move to
417 particular header fields and to complete addresses in headers.
421 Move to the @samp{To} header (@code{message-goto-to}).
423 Move to the @samp{Subject} header (@code{message-goto-subject}).
425 Move to the @samp{CC} header (@code{message-goto-cc}).
427 Move to the @samp{BCC} header (@code{message-goto-bcc}).
429 Move to the @samp{Reply-To} header (@code{message-goto-reply-to}).
431 Move to the @samp{Mail-Followup-To} header field
432 (@code{message-goto-followup-to}).
434 Add a new @samp{FCC} header field, with file-name completion
435 (@code{message-goto-fcc}).
437 Move to the start of the message body (@code{message-goto-body}).
439 Complete a mailing address (@code{message-tab}).
442 @kindex C-c C-f C-t @r{(Message mode)}
443 @findex message-goto-to
444 @kindex C-c C-f C-s @r{(Message mode)}
445 @findex message-goto-subject
446 @kindex C-c C-f C-c @r{(Message mode)}
447 @findex message-goto-cc
448 @kindex C-c C-f C-b @r{(Message mode)}
449 @findex message-goto-bcc
450 @kindex C-c C-f C-r @r{(Message mode)}
451 @findex goto-reply-to
452 @kindex C-c C-f C-f @r{(Message mode)}
453 @findex goto-followup-to
454 @kindex C-c C-f C-w @r{(Message mode)}
455 @findex message-goto-fcc
456 The commands to move point to particular header fields are all based
457 on the prefix @kbd{C-c C-f} (@samp{C-f} is for ``field''). If the
458 field in question does not exist, the command creates one (the
459 exception is @code{mail-fcc}, which creates a new field each time).
461 @kindex C-c C-b @r{(Message mode)}
463 The command @kbd{C-c C-b} (@code{message-goto-body}) moves point to
464 just after the header separator line---that is, to the beginning of
468 @kindex TAB @r{(Message mode)}
469 While editing a header field that contains addresses, such as
470 @samp{To:}, @samp{CC:} and @samp{BCC:}, you can complete an address by
471 typing @key{TAB} (@code{message-tab}). This attempts to insert the
472 full name corresponding to the address based on a couple of methods,
473 including EUDC, a library that recognizes a number of directory server
474 protocols (@pxref{Top,,EUDC,eudc, The Emacs Unified Directory
475 Client}). Failing that, it attempts to expand the address as a mail
476 alias (@pxref{Mail Aliases}). If point is on a header field that does
477 not take addresses, or if it is in the message body, then @key{TAB}
478 just inserts a tab character.
481 @subsection Citing Mail
486 Yank the selected message from the mail reader, as a citation
487 (@code{message-yank-original}).
489 Fill each paragraph cited from another message
490 (@code{message-fill-yanked-message}).
493 @kindex C-c C-y @r{(Message mode)}
494 @findex message-yank-original
495 @findex message-yank-prefix
496 You can use the command @kbd{C-c C-y} (@code{message-yank-original})
497 to @dfn{cite} a message that you are replying to. This inserts the
498 text of that message into the mail buffer. This command works only if
499 the mail buffer is invoked from a mail reader running in Emacs, such
502 By default, Emacs inserts the string @samp{>} in front of each line
503 of the cited text; this prefix string is specified by the variable
504 @code{message-yank-prefix}. If you call @code{message-yank-original}
505 with a prefix argument, the citation prefix is not inserted.
507 @kindex C-c C-q @r{(Message mode)}
508 @findex mail-fill-yanked-message
509 After using @kbd{C-c C-y}, you can type @kbd{C-c C-q}
510 (@code{message-fill-yanked-message}) to fill the paragraphs of the
511 cited message. One use of @kbd{C-c C-q} fills all such paragraphs,
512 each one individually. To fill a single paragraph of the quoted
513 message, use @kbd{M-q}. If filling does not automatically handle the
514 type of citation prefix you use, try setting the fill prefix
515 explicitly. @xref{Filling}.
517 @vindex mail-citation-hook
518 You can customize mail citation through the hook
519 @code{mail-citation-hook}. For example, you can use the Supercite
520 package, which provides more flexible citation
521 (@pxref{Introduction,,,sc, Supercite}).
524 @subsection Mail Miscellany
526 @kindex C-c C-a @r{(Message mode)}
527 @findex mail-attach-file
529 @cindex Multipurpose Internet Mail Extensions
530 You can @dfn{attach} a file to an outgoing message by typing
531 @kbd{C-c C-a} (@code{mml-attach-file}) in the mail buffer. Attaching
532 is done using the Multipurpose Internet Mail Extensions
533 (@acronym{MIME}) standard.
535 The @code{mml-attach-file} command prompts for the name of the file,
536 and for the attachment's @dfn{content type}, @dfn{description}, and
537 @dfn{disposition}. The content type is normally detected
538 automatically; just type @key{RET} to accept the default. The
539 description is a single line of text that the recipient will see next
540 to the attachment; you may also choose to leave this empty. The
541 disposition is either @samp{inline} (the default), which means the
542 recipient will see a link to the attachment within the message body,
543 or @samp{attachment}, which means the link will be separate from the
546 @findex mail-add-attachment
547 The @code{mml-attach-file} command is specific to Message mode; in
548 Mail mode use @kbd{mail-add-attachment} instead. It will prompt only
549 for the name of the file, and will determine the content type and the
550 disposition automatically. If you want to include some description of
551 the attached file, type that in the message body.
553 The actual contents of the attached file are not inserted into the
554 mail buffer. Instead, some placeholder text is inserted into the mail
558 <#part type="text/plain" filename="~/foo.txt" disposition=inline>
563 When you type @kbd{C-c C-c} or @kbd{C-c C-s} to send the message, the
564 attached file will be delivered with it.
566 @findex ispell-message
567 While composing a message, you can do spelling correction on the
568 message text by typing @kbd{M-x ispell-message}. If you have yanked
569 an incoming message into the outgoing draft, this command skips what
570 was yanked, but it checks the text that you yourself inserted (it
571 looks for indentation or @code{mail-yank-prefix} to distinguish the
572 cited lines from your input). @xref{Spelling}.
574 @vindex mail-mode-hook
575 @vindex mail-setup-hook
576 Turning on Message mode (which @kbd{C-x m} does automatically) runs
577 the normal hooks @code{text-mode-hook} and @code{message-mode-hook}.
578 Initializing a new outgoing message runs the normal hook
579 @code{message-setup-hook}; you can use this hook if you want to make
580 changes to the appearance of the mail buffer. @xref{Hooks}.
582 The main difference between these hooks is just when they are
583 invoked. Whenever you type @kbd{C-x m}, @code{message-mode-hook} runs
584 as soon as the mail buffer is created. Then the @code{message-setup}
585 function inserts the default contents of the buffer. After these
586 default contents are inserted, @code{message-setup-hook} runs.
588 If you use @kbd{C-x m} to continue an existing composition,
589 @code{message-mode-hook} runs immediately after switching to the mail
590 buffer. If the buffer is unmodified, or if you decide to erase it and
591 start again, @code{message-setup-hook} runs after the default contents
595 @section Mail Signature
597 @cindex mail signature
598 @vindex mail-signature-file
599 @vindex mail-signature
600 You can add a standard piece of text---your @dfn{mail
601 signature}---to the end of every message. This signature may contain
602 information such as your telephone number or your physical location.
603 The variable @code{mail-signature} determines how Emacs handles the
606 The default value of @code{mail-signature} is @code{t}; this means
607 to look for your mail signature in the file @file{~/.signature}. If
608 this file exists, its contents are automatically inserted into the end
609 of the mail buffer. You can change the signature file via the
610 variable @code{mail-signature-file}.
612 If you change @code{mail-signature} to a string, that specifies the
613 text of the signature directly.
615 @kindex C-c C-w @r{(Message mode)}
616 @findex message-insert-signature
617 If you change @code{mail-signature} to @code{nil}, Emacs will not
618 insert your mail signature automatically. You can insert your mail
619 signature by typing @kbd{C-c C-w} (@code{message-insert-signature}) in
620 the mail buffer. Emacs will look for your signature in the signature
623 By convention, a mail signature should be marked by a line whose
624 contents are @samp{-- }. If your signature lacks this prefix, it is
625 added for you. The remainder of your signature should be no more than
628 @node Mail Amusements
629 @section Mail Amusements
633 @kbd{M-x spook} adds a line of randomly chosen keywords to an outgoing
634 mail message. The keywords are chosen from a list of words that suggest
635 you are discussing something subversive.
637 The idea behind this feature is the suspicion that the
638 NSA@footnote{The US National Security Agency.} and other intelligence
639 agencies snoop on all electronic mail messages that contain keywords
640 suggesting they might find them interesting. (The agencies say that
641 they don't, but that's what they @emph{would} say.) The idea is that if
642 lots of people add suspicious words to their messages, the agencies will
643 get so busy with spurious input that they will have to give up reading
644 it all. Whether or not this is true, it at least amuses some people.
646 @findex fortune-to-signature
647 @cindex fortune cookies
648 You can use the @code{fortune} program to put a ``fortune cookie''
649 message into outgoing mail. To do this, add
650 @code{fortune-to-signature} to @code{mail-setup-hook}:
653 (add-hook 'mail-setup-hook 'fortune-to-signature)
657 You will probably need to set the variable @code{fortune-file} before
661 @section Mail-Composition Methods
662 @cindex mail-composition methods
666 @cindex MH mail interface
667 @cindex Message mode for sending mail
668 In this chapter we have described the usual Emacs mode for editing
669 and sending mail---Message mode. This is only one of several
670 available modes. Prior to Emacs 23.2, the default mode was Mail mode,
671 which is similar to Message mode in many respects but lacks features
672 such as MIME support. Another available mode is MH-E
673 (@pxref{Top,,MH-E,mh-e, The Emacs Interface to MH}).
675 @vindex mail-user-agent
676 You can choose any of these @dfn{mail user agents} as your preferred
677 method for editing and sending mail. The commands @code{C-x m},
678 @code{C-x 4 m} and @code{C-x 5 m} use whichever agent you have
679 specified; so do various other parts of Emacs that send mail, such as
680 the bug reporter (@pxref{Bugs}). To specify a mail user agent,
681 customize the variable @code{mail-user-agent}. Currently, legitimate
682 values include @code{message-user-agent} (Message mode)
683 @code{sendmail-user-agent} (Mail mode), @code{gnus-user-agent}, and
684 @code{mh-e-user-agent}.
686 If you select a different mail-composition method, the information
687 in this chapter about the mail buffer and Message mode does not apply;
688 the other methods use a different format of text in a different
689 buffer, and their commands are different as well.
691 @vindex read-mail-command
692 Similarly, to specify your preferred method for reading mail,
693 customize the variable @code{read-mail-command}. The default is
694 @code{rmail} (@pxref{Rmail}).