@c This is part of the Emacs manual.@c Copyright (C) 1985,86,87,93,94,95,97,2000,2001@c Free Software Foundation, Inc.@c See file emacs.texi for copying conditions.@node Sending Mail, Rmail, Picture, Top@chapter Sending Mail@cindex sending mail@cindex mail@cindex message To send a message in Emacs, you start by typing a command (@kbd{C-x m})to select and initialize the @samp{*mail*} buffer. Then you edit the textand headers of the message in this buffer, and type another command(@kbd{C-c C-s} or @kbd{C-c C-c}) to send the message.@table @kbd@item C-x mBegin composing a message to send (@code{compose-mail}).@item C-x 4 mLikewise, but display the message in another window(@code{compose-mail-other-window}).@item C-x 5 mLikewise, but make a new frame (@code{compose-mail-other-frame}).@item C-c C-sIn Mail mode, send the message (@code{mail-send}).@item C-c C-cSend the message and bury the mail buffer (@code{mail-send-and-exit}).@end table@kindex C-x m@findex compose-mail@kindex C-x 4 m@findex compose-mail-other-window@kindex C-x 5 m@findex compose-mail-other-frame The command @kbd{C-x m} (@code{compose-mail}) selects a buffer named@samp{*mail*} and initializes it with the skeleton of an outgoingmessage. @kbd{C-x 4 m} (@code{compose-mail-other-window}) selects the@samp{*mail*} buffer in a different window, leaving the previous currentbuffer visible. @kbd{C-x 5 m} (@code{compose-mail-other-frame}) createsa new frame to select the @samp{*mail*} buffer. Because the mail-composition buffer is an ordinary Emacs buffer, you canswitch to other buffers while in the middle of composing mail, and switchback later (or never). If you use the @kbd{C-x m} command again when youhave been composing another message but have not sent it, you are asked toconfirm before the old message is erased. If you answer @kbd{n}, the@samp{*mail*} buffer is left selected with its old contents, so you canfinish the old message and send it. @kbd{C-u C-x m} is another way to dothis. Sending the message marks the @samp{*mail*} buffer ``unmodified,''which avoids the need for confirmation when @kbd{C-x m} is next used. If you are composing a message in the @samp{*mail*} buffer and want tosend another message before finishing the first, rename the@samp{*mail*} buffer using @kbd{M-x rename-uniquely} (@pxref{MiscBuffer}). Then you can use @kbd{C-x m} or its variants described aboveto make a new @samp{*mail*} buffer. Once you've done that, you can workwith each mail buffer independently.@ignore@c Commented out because it is not user-oriented;@c it doesn't say how to do some job. -- rms.@cindex directory servers@cindex LDAP@cindex PH/QI@cindex names and addressesThere is an interface to directory servers using various protocols suchas LDAP or the CCSO white pages directory system (PH/QI), described in aseparate manual. It may be useful for looking up names and addresses.@xref{Top,,EUDC, eudc, EUDC Manual}.@end ignore@menu* Format: Mail Format. Format of the mail being composed.* Headers: Mail Headers. Details of permitted mail header fields.* Aliases: Mail Aliases. Abbreviating and grouping mail addresses.* Mode: Mail Mode. Special commands for editing mail being composed.* Amuse: Mail Amusements. Distracting the NSA; adding fortune messages.* Methods: Mail Methods. Using alternative mail-composition methods.@end menu@node Mail Format@section The Format of the Mail Buffer In addition to the @dfn{text} or @dfn{body}, a message has @dfn{headerfields} which say who sent it, when, to whom, why, and so on. Someheader fields, such as @samp{Date} and @samp{Sender}, are createdautomatically when you send the message. Others, such as the recipientnames, must be specified by you in order to send the message properly. Mail mode provides a few commands to help you edit some header fields,and some are preinitialized in the buffer automatically at times. You caninsert and edit header fields using ordinary editing commands. The line in the buffer that says@example--text follows this line--@end example@noindentis a special delimiter that separates the headers you have specified fromthe text. Whatever follows this line is the text of the message; theheaders precede it. The delimiter line itself does not appear in themessage actually sent. The text used for the delimiter line is controlledby the variable @code{mail-header-separator}.Here is an example of what the headers and text in the mail buffermight look like.@exampleTo: gnu@@gnu.orgCC: lungfish@@spam.org, byob@@spam.orgSubject: The Emacs Manual--Text follows this line--Please ignore this message.@end example@node Mail Headers@section Mail Header Fields@cindex headers (of mail message) A header field in the mail buffer starts with a field name at thebeginning of a line, terminated by a colon. Upper and lower case areequivalent in field names (and in mailing addresses also). After thecolon and optional whitespace comes the contents of the field. You can use any name you like for a header field, but normally peopleuse only standard field names with accepted meanings. Here is a tableof fields commonly used in outgoing messages.@table @samp@item ToThis field contains the mailing addresses to which the message isaddressed. If you list more than one address, use commas, not spaces,to separate them.@item SubjectThe contents of the @samp{Subject} field should be a piece of textthat says what the message is about. The reason @samp{Subject} fieldsare useful is that most mail-reading programs can provide a summary ofmessages, listing the subject of each message but not its text.@item CCThis field contains additional mailing addresses to send the message to,like @samp{To} except that these readers should not regard the messageas directed at them.@item BCCThis field contains additional mailing addresses to send the message to,which should not appear in the header of the message actually sent.Copies sent this way are called @dfn{blind carbon copies}.@vindex mail-self-blind@cindex copy of every outgoing messageTo send a blind carbon copy of every outgoing message to yourself, setthe variable @code{mail-self-blind} to @code{t}. To send a blind carboncopy of every message to some other @var{address}, set the variable@code{mail-default-headers} to @code{"Bcc: @var{address}\n"}.@item FCCThis field contains the name of one file and directs Emacs to append acopy of the message to that file when you send the message. If the fileis in Rmail format, Emacs writes the message in Rmail format; otherwise,Emacs writes the message in system mail file format. To specifymore than one file, use several @samp{FCC} fields, with one filename in each field.@vindex mail-archive-file-nameTo put a fixed file name in the @samp{FCC} field each time you startediting an outgoing message, set the variable@code{mail-archive-file-name} to that file name. Unless you remove the@samp{FCC} field before sending, the message will be written into thatfile when it is sent.@item FromUse the @samp{From} field to say who you are, when the account you areusing to send the mail is not your own. The contents of the @samp{From}field should be a valid mailing address, since replies will normally gothere. If you don't specify the @samp{From} field yourself, Emacs usesthe value of @code{user-mail-address} as the default.@item Reply-toUse this field to direct replies to a different address. Mostmail-reading programs (including Rmail) automatically send replies tothe @samp{Reply-to} address in preference to the @samp{From} address.By adding a @samp{Reply-to} field to your header, you can work aroundany problems your @samp{From} address may cause for replies.@cindex @env{REPLYTO} environment variable@vindex mail-default-reply-toTo put a fixed @samp{Reply-to} address into every outgoing message, setthe variable @code{mail-default-reply-to} to that address (as a string).Then @code{mail} initializes the message with a @samp{Reply-to} field asspecified. You can delete or alter that header field before you sendthe message, if you wish. When Emacs starts up, if the environmentvariable @env{REPLYTO} is set, @code{mail-default-reply-to} isinitialized from that environment variable.@item In-reply-toThis field contains a piece of text describing the message you arereplying to. Some mail systems can use this information to correlaterelated pieces of mail. Normally this field is filled in by Rmailwhen you reply to a message in Rmail, and you never need tothink about it (@pxref{Rmail}).@item ReferencesThis field lists the message IDs of related previous messages. Rmailsets up this field automatically when you reply to a message.@end table The @samp{To}, @samp{CC}, and @samp{BCC} header fields can appearany number of times, and each such header field can contain multipleaddresses, separated by commas. This way, you can specify any numberof places to send the message. These fields can also havecontinuation lines: one or more lines starting with whitespace,following the starting line of the field, are considered part of thefield. Here's an example of a @samp{To} field with a continuationline:@refill@example@groupTo: foo@@here.net, this@@there.net, me@@gnu.cambridge.mass.usa.earth.spiral3281@end group@end example@vindex mail-from-style When you send the message, if you didn't write a @samp{From} fieldyourself, Emacs puts in one for you. The variable@code{mail-from-style} controls the format:@table @code@item nilUse just the email address, as in @samp{king@@grassland.com}.@item parensUse both email address and full name, as in @samp{king@@grassland.com (ElvisParsley)}.@item anglesUse both email address and full name, as in @samp{Elvis Parsley<king@@grassland.com>}.@item system-defaultAllow the system to insert the @samp{From} field.@end table@vindex mail-default-headers You can direct Emacs to insert certain default headers into theoutgoing message by setting the variable @code{mail-default-headers}to a string. Then @code{C-x m} inserts this string into the messageheaders. If the default header fields are not appropriate for aparticular message, edit them as appropriate before sending themessage.@node Mail Aliases@section Mail Aliases@cindex mail aliases@cindex @file{.mailrc} file@cindex mailrc file You can define @dfn{mail aliases} in a file named @file{~/.mailrc}.These are short mnemonic names which stand for mail addresses or groups ofmail addresses. Like many other mail programs, Emacs expands aliaseswhen they occur in the @samp{To}, @samp{From}, @samp{CC}, @samp{BCC}, and@samp{Reply-to} fields, plus their @samp{Resent-} variants. To define an alias in @file{~/.mailrc}, write a line in the followingformat:@examplealias @var{shortaddress} @var{fulladdresses}@end example@noindentHere @var{fulladdresses} stands for one or more mail addresses for@var{shortaddress} to expand into. Separate multiple addresses withspaces; if an address contains a space, quote the whole address with apair of double-quotes.For instance, to make @code{maingnu} stand for@code{gnu@@gnu.org} plus a local address of your own, put inthis line:@refill@examplealias maingnu gnu@@gnu.org local-gnu@end example Emacs also recognizes include commands in @samp{.mailrc} files.They look like this:@examplesource @var{filename}@end example@noindentThe file @file{~/.mailrc} is used primarily by other mail-readingprograms; it can contain various other commands. Emacs ignoreseverything in it except for alias definitions and include commands.@findex define-mail-alias Another way to define a mail alias, within Emacs alone, is with the@code{define-mail-alias} command. It prompts for the alias and then thefull address. You can use it to define aliases in your @file{.emacs}file, like this:@example(define-mail-alias "maingnu" "gnu@@gnu.org")@end example@vindex mail-aliases @code{define-mail-alias} records aliases by adding them to avariable named @code{mail-aliases}. If you are comfortable withmanipulating Lisp lists, you can set @code{mail-aliases} directly. Theinitial value of @code{mail-aliases} is @code{t}, which means thatEmacs should read @file{.mailrc} to get the proper value.@vindex mail-personal-alias-file You can specify a different file name to use instead of@file{~/.mailrc} by setting the variable@code{mail-personal-alias-file}.@findex expand-mail-aliases Normally, Emacs expands aliases when you send the message. You do notneed to expand mail aliases before sending the message, but you canexpand them if you want to see where the mail will actually go. To dothis, use the command @kbd{M-x expand-mail-aliases}; it expands all mailaliases currently present in the mail headers that hold addresses. If you like, you can have mail aliases expand as abbrevs, as soon asyou type them in (@pxref{Abbrevs}). To enable this feature, execute thefollowing:@example(add-hook 'mail-mode-hook 'mail-abbrevs-setup)@end example@noindent@findex define-mail-abbrev@vindex mail-abbrevsThis can go in your @file{.emacs} file. @xref{Hooks}. If you use thisfeature, you must use @code{define-mail-abbrev} instead of@code{define-mail-alias}; the latter does not work with this package.Note that the mail abbreviation package uses the variable@code{mail-abbrevs} instead of @code{mail-aliases}, and that all aliasnames are converted to lower case.@kindex C-c C-a @r{(Mail mode)}@findex mail-interactive-insert-alias The mail abbreviation package also provides the @kbd{C-c C-a}(@code{mail-interactive-insert-alias}) command, which reads an aliasname (with completion) and inserts its definition at point. This isuseful when editing the message text itself or a header field such as@samp{Subject} in which Emacs does not normally expand aliases. Note that abbrevs expand only if you insert a word-separator characterafterward. However, you can rebind @kbd{C-n} and @kbd{M->} to causeexpansion as well. Here's how to do that:@smallexample(add-hook 'mail-mode-hook (lambda () (substitute-key-definition 'next-line 'mail-abbrev-next-line mail-mode-map global-map) (substitute-key-definition 'end-of-buffer 'mail-abbrev-end-of-buffer mail-mode-map global-map)))@end smallexample@node Mail Mode@section Mail Mode@cindex Mail mode@cindex mode, Mail The major mode used in the mail buffer is Mail mode, which is muchlike Text mode except that various special commands are provided on the@kbd{C-c} prefix. These commands all have to do specifically withediting or sending the message. In addition, Mail mode defines thecharacter @samp{%} as a word separator; this is helpful for using theword commands to edit mail addresses. Mail mode is normally used in buffers set up automatically by the@code{mail} command and related commands. However, you can also switchto Mail mode in a file-visiting buffer. This is a useful thing to do ifyou have saved the text of a draft message in a file.@menu* Mail Sending:: Commands to send the message.* Header Editing:: Commands to move to header fields and edit them.* Citing Mail:: Copying all or part of a message you are replying to.* Mail Mode Misc:: Spell checking, signatures, etc.@end menu@node Mail Sending@subsection Mail Sending Mail mode has two commands for sending the message you have beenediting:@table @kbd@item C-c C-sSend the message, and leave the mail buffer selected (@code{mail-send}).@item C-c C-cSend the message, and select some other buffer (@code{mail-send-and-exit}).@end table@kindex C-c C-s @r{(Mail mode)}@kindex C-c C-c @r{(Mail mode)}@findex mail-send@findex mail-send-and-exit @kbd{C-c C-s} (@code{mail-send}) sends the message and marks the mailbuffer unmodified, but leaves that buffer selected so that you canmodify the message (perhaps with new recipients) and send it again.@kbd{C-c C-c} (@code{mail-send-and-exit}) sends and then deletes thewindow or switches to another buffer. It puts the mail buffer at thelowest priority for reselection by default, since you are finished withusing it. This is the usual way to send the message. In a file-visiting buffer, sending the message does not clear themodified flag, because only saving the file should do that. As aresult, you don't get a warning if you try to send the same messagetwice.@c This is indexed in mule.texi, node "Recognize Coding".@c @vindex sendmail-coding-system When you send a message that contains non-ASCII characters, they needto be encoded with a coding system (@pxref{Coding Systems}). Usuallythe coding system is specified automatically by your chosen languageenvironment (@pxref{Language Environments}). You can explicitly specifythe coding system for outgoing mail by setting the variable@code{sendmail-coding-system} (@pxref{Recognize Coding}). If the coding system thus determined does not handle the characters ina particular message, Emacs asks you to select the coding system to use,showing a list of possible coding systems.@node Header Editing@subsection Mail Header Editing Mail mode provides special commands to move to particular headerfields and to complete addresses in headers.@table @kbd@item C-c C-f C-tMove to the @samp{To} header field, creating one if there is none(@code{mail-to}).@item C-c C-f C-sMove to the @samp{Subject} header field, creating one if there isnone (@code{mail-subject}).@item C-c C-f C-cMove to the @samp{CC} header field, creating one if there is none(@code{mail-cc}).@item C-c C-f C-bMove to the @samp{BCC} header field, creating one if there is none(@code{mail-bcc}).@item C-c C-f C-fMove to the @samp{FCC} header field, creating one if there is none(@code{mail-fcc}).@item M-@key{TAB}Complete a mailing address (@code{mail-complete}).@end table@kindex C-c C-f C-t @r{(Mail mode)}@findex mail-to@kindex C-c C-f C-s @r{(Mail mode)}@findex mail-subject@kindex C-c C-f C-c @r{(Mail mode)}@findex mail-cc@kindex C-c C-f C-b @r{(Mail mode)}@findex mail-bcc@kindex C-c C-f C-f @r{(Mail mode)}@findex mail-fcc There are five commands to move point to particular header fields, allbased on the prefix @kbd{C-c C-f} (@samp{C-f} is for ``field''). Theyare listed in the table above. If the field in question does not exist,these commands create one. We provide special motion commands for theseparticular fields because they are the fields users most often want toedit.@findex mail-complete@kindex M-TAB @r{(Mail mode)} While editing a header field that contains mailing addresses, such as@samp{To:}, @samp{CC:} and @samp{BCC:}, you can complete a mailingaddress by typing @kbd{M-@key{TAB}} (@code{mail-complete}). It insertsthe full name corresponding to the address, if it can determine the fullname. The variable @code{mail-complete-style} controls whether to insertthe full name, and what style to use, as in @code{mail-from-style}(@pxref{Mail Headers}). For completion purposes, the valid mailing addresses are taken to bethe local users' names plus your personal mail aliases. You canspecify additional sources of valid addresses; look at the customizationgroup @samp{mailalias} to see the options for this(@pxref{Customization Groups}). If you type @kbd{M-@key{TAB}} in the body of the message,@code{mail-complete} invokes @code{ispell-complete-word}, as in Textmode.@node Citing Mail@subsection Citing Mail@cindex citing mail Mail mode also has commands for yanking or @dfn{citing} all or part ofa message that you are replying to. These commands are active only whenyou started sending a message using an Rmail command.@table @kbd@item C-c C-yYank the selected message from Rmail (@code{mail-yank-original}).@item C-c C-rYank the region from the Rmail buffer (@code{mail-yank-region}).@item C-c C-qFill each paragraph cited from another message(@code{mail-fill-yanked-message}).@end table@kindex C-c C-y @r{(Mail mode)}@findex mail-yank-original When mail sending is invoked from the Rmail mail reader using an Rmailcommand, @kbd{C-c C-y} can be used inside the mail buffer to insertthe text of the message you are replying to. Normally it indents each lineof that message three spaces and eliminates most header fields. A numericargument specifies the number of spaces to indent. An argument of just@kbd{C-u} says not to indent at all and not to eliminate anything.@kbd{C-c C-y} always uses the current message from the Rmail buffer,so you can insert several old messages by selecting one in Rmail,switching to @samp{*mail*} and yanking it, then switching back toRmail to select another.@vindex mail-yank-prefix You can specify the text for @kbd{C-c C-y} to insert at the beginningof each line: set @code{mail-yank-prefix} to the desired string. (Avalue of @code{nil} means to use indentation; this is the default.)However, @kbd{C-u C-c C-y} never adds anything at the beginning of theinserted lines, regardless of the value of @code{mail-yank-prefix}.@kindex C-c C-r @r{(Mail mode)}@findex mail-yank-region To yank just a part of an incoming message, set the region in Rmail tothe part you want; then go to the @samp{*Mail*} message and type@kbd{C-c C-r} (@code{mail-yank-region}). Each line that is copied isindented or prefixed according to @code{mail-yank-prefix}.@kindex C-c C-q @r{(Mail mode)}@findex mail-fill-yanked-message After using @kbd{C-c C-y} or @kbd{C-c C-r}, you can type @kbd{C-c C-q}(@code{mail-fill-yanked-message}) to fill the paragraphs of the yankedold message or messages. One use of @kbd{C-c C-q} fills all suchparagraphs, each one individually. To fill a single paragraph of thequoted message, use @kbd{M-q}. If filling does not automaticallyhandle the type of citation prefix you use, try setting the fill prefixexplicitly. @xref{Filling}.@node Mail Mode Misc@subsection Mail Mode Miscellany@table @kbd@item C-c C-tMove to the beginning of the message body text (@code{mail-text}).@item C-c C-wInsert the file @file{~/.signature} at the end of the message text(@code{mail-signature}).@item C-c C-i @var{file} @key{RET}Insert the contents of @var{file} at the end of the outgoing message(@code{mail-attach-file}).@item M-x ispell-messagePerform spelling correction on the message text, but not on citations fromother messages.@end table@kindex C-c C-t @r{(Mail mode)}@findex mail-text @kbd{C-c C-t} (@code{mail-text}) moves point to just after the headerseparator line---that is, to the beginning of the message body text.@kindex C-c C-w @r{(Mail mode)}@findex mail-signature@vindex mail-signature @kbd{C-c C-w} (@code{mail-signature}) adds a standard piece of text atthe end of the message to say more about who you are. The text comesfrom the file @file{~/.signature} in your home directory. To insertyour signature automatically, set the variable @code{mail-signature} to@code{t}; after that, starting a mail message automatically inserts thecontents of your @file{~/.signature} file. If you want to omit yoursignature from a particular message, delete it from the buffer beforeyou send the message. You can also set @code{mail-signature} to a string; then that stringis inserted automatically as your signature when you start editing amessage to send. If you set it to some other Lisp expression, theexpression is evaluated each time, and its value (which should be astring) specifies the signature.@findex ispell-message You can do spelling correction on the message text you have writtenwith the command @kbd{M-x ispell-message}. If you have yanked anincoming message into the outgoing draft, this command skips what wasyanked, but it checks the text that you yourself inserted. (It looksfor indentation or @code{mail-yank-prefix} to distinguish the citedlines from your input.) @xref{Spelling}.@kindex C-c C-i @r{(Mail mode)}@findex mail-attach-file To include a file in the outgoing message, you can use @kbd{C-x i},the usual command to insert a file in the current buffer. But it isoften more convenient to use a special command, @kbd{C-c C-i}(@code{mail-attach-file}). This command inserts the file contents atthe end of the buffer, after your signature if any, with a delimiterline that includes the file name.@vindex mail-mode-hook@vindex mail-setup-hook Turning on Mail mode (which @kbd{C-x m} does automatically) runs thenormal hooks @code{text-mode-hook} and @code{mail-mode-hook}.Initializing a new outgoing message runs the normal hook@code{mail-setup-hook}; if you want to add special fields to your mailheader or make other changes to the appearance of the mail buffer, usethat hook. @xref{Hooks}. The main difference between these hooks is just when they areinvoked. Whenever you type @kbd{M-x mail}, @code{mail-mode-hook} runsas soon as the @samp{*mail*} buffer is created. Then the@code{mail-setup} function inserts the default contents of the buffer.After these default contents are inserted, @code{mail-setup-hook} runs.@node Mail Amusements@section Mail Amusements@findex spook@cindex NSA @kbd{M-x spook} adds a line of randomly chosen keywords to an outgoingmail message. The keywords are chosen from a list of words that suggestyou are discussing something subversive. The idea behind this feature is the suspicion that theNSA@footnote{The US National Security Agency.} snoops onall electronic mail messages that contain keywords suggesting they mightfind them interesting. (The NSA says they don't, but that's what they@emph{would} say.) The idea is that if lots of people add suspiciouswords to their messages, the NSA will get so busy with spurious inputthat they will have to give up reading it all. Here's how to insert spook keywords automatically whenever you startentering an outgoing message:@example(add-hook 'mail-setup-hook 'spook)@end example Whether or not this confuses the NSA, it at least amuses people.@findex fortune-to-signature@cindex fortune cookies You can use the @code{fortune} program to put a ``fortune cookie''message into outgoing mail. To do this, add@code{fortune-to-signature} to @code{mail-setup-hook}:@example(add-hook 'mail-setup-hook 'fortune-to-signature)@end example@node Mail Methods@section Mail-Composition Methods@cindex mail-composition methods@cindex MH mail interface@cindex Message mode for sending mail In this chapter we have described the usual Emacs mode for editingand sending mail---Mail mode. Emacs has alternative facilities forediting and sending mail, includingMH-E and Message mode, not documented in this manual.@xref{MH-E,,,mh-e, The Emacs Interface to MH}. @xref{Message,,,message,Message Manual}. You can choose any of them as your preferred method.The commands @code{C-x m}, @code{C-x 4 m} and @code{C-x 5 m} usewhichever agent you have specified, as do various other Emacs commandsand facilities that send mail.@vindex mail-user-agent To specify your mail-composition method, customize the variable@code{mail-user-agent}. Currently legitimate values include@code{sendmail-user-agent} (Mail mode), @code{mh-e-user-agent},@code{message-user-agent} and @code{gnus-user-agent}. If you select a different mail-composition method, the informationin this chapter about the @samp{*mail*} buffer and Mail mode does notapply; the other methods use a different format of text in a differentbuffer, and their commands are different as well.