Fix minor whitespace issues after "." in manual.
[bpt/emacs.git] / doc / misc / smtpmail.texi
CommitLineData
4009494e 1\input texinfo @c -*-texinfo-*-
db78a8cb 2@setfilename ../../info/smtpmail
4009494e
GM
3@settitle Emacs SMTP Library
4@syncodeindex vr fn
5@copying
acaf905b 6Copyright @copyright{} 2003-2012
3f548a7c 7Free Software Foundation, Inc.
4009494e
GM
8
9@quotation
10Permission is granted to copy, distribute and/or modify this document
6a2c4aec 11under the terms of the GNU Free Documentation License, Version 1.3 or
4009494e
GM
12any later version published by the Free Software Foundation; with no
13Invariant Sections, with the Front-Cover texts being ``A GNU Manual'',
14and with the Back-Cover Texts as in (a) below. A copy of the license
debf4439 15is included in the section entitled ``GNU Free Documentation License''.
4009494e 16
6f093307
GM
17(a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
18modify this GNU manual. Buying copies from the FSF supports it in
19developing GNU and promoting software freedom.''
4009494e
GM
20@end quotation
21@end copying
22
0c973505 23@dircategory Emacs lisp libraries
4009494e 24@direntry
62e034c2 25* SMTP: (smtpmail). Emacs library for sending mail via SMTP.
4009494e
GM
26@end direntry
27
28@titlepage
29@title{Emacs SMTP Library}
30@subtitle{An Emacs package for sending mail via SMTP}
31@author{Simon Josefsson, Alex Schroeder}
32@page
33@vskip 0pt plus 1filll
34@insertcopying
35@end titlepage
36
37@contents
38
39@ifnottex
40@node Top
41@top Emacs SMTP Library
42
43@insertcopying
44@end ifnottex
45
46@menu
9360256a 47* How Mail Works:: Brief introduction to mail concepts.
4009494e 48* Emacs Speaks SMTP:: How to use the SMTP library in Emacs.
9360256a 49* Authentication:: Authenticating yourself to the server.
9f26dc24 50* Encryption:: Protecting your connection to the server.
9360256a
GM
51* Queued delivery:: Sending mail without an internet connection.
52* Server workarounds:: Mail servers with special requirements.
53* Debugging:: Tracking down problems.
4009494e
GM
54* GNU Free Documentation License:: The license for this documentation.
55
56Indices
57
9360256a 58* Index:: Index over variables and functions.
4009494e
GM
59@end menu
60
61@node How Mail Works
62@chapter How Mail Works
63
64@cindex SMTP
65@cindex MTA
66 On the internet, mail is sent from mail host to mail host using the
67simple mail transfer protocol (SMTP). To send and receive mail, you
68must get it from and send it to a mail host. Every mail host runs a
69mail transfer agent (MTA) such as Exim that accepts mails and passes
70them on. The communication between a mail host and other clients does
71not necessarily involve SMTP, however. Here is short overview of what
72is involved.
73
74@cindex MUA
75 The mail program --- also called a mail user agent (MUA) ---
76usually sends outgoing mail to a mail host. When your computer is
77permanently connected to the internet, it might even be a mail host
78itself. In this case, the MUA will pipe mail to the
79@file{/usr/lib/sendmail} application. It will take care of your mail
80and pass it on to the next mail host.
81
82@cindex ISP
83 When you are only connected to the internet from time to time, your
84internet service provider (ISP) has probably told you which mail host
85to use. You must configure your MUA to use that mail host. Since you
86are reading this manual, you probably want to configure Emacs to use
87SMTP to send mail to that mail host. More on that in the next
88section.
89
90@cindex MDA
91 Things are different when reading mail. The mail host responsible
92for your mail keeps it in a file somewhere. The messages get into the
93file by way of a mail delivery agent (MDA) such as procmail. These
94delivery agents often allow you to filter and munge your mails before
95you get to see it. When your computer is that mail host, this file is
96called a spool, and sometimes located in the directory
97@file{/var/spool/mail/}. All your MUA has to do is read mail from the
98spool, then.
99
100@cindex POP3
101@cindex IMAP
102 When your computer is not always connected to the internet, you
103must get the mail from the remote mail host using a protocol such as
1df7defd 104POP3 or IMAP@. POP3 essentially downloads all your mail from the mail
4009494e
GM
105host to your computer. The mail is stored in some file on your
106computer, and again, all your MUA has to do is read mail from the
107spool.
108
109 When you read mail from various machines, downloading mail from the
110mail host to your current machine is not convenient. In that case,
111you will probably want to use the IMAP protocol. Your mail is kept on
112the mail host, and you can read it while you are connected via IMAP to
113the mail host.
114
115@cindex Webmail
116 So how does reading mail via the web work, you ask. In that case,
117the web interface just allows you to remote-control a MUA on the web
118host. Whether the web host is also a mail host, and how all the
119pieces interact is completely irrelevant. You usually cannot use
120Emacs to read mail via the web, unless you use software that parses
121the ever-changing HTML of the web interface.
122
123@node Emacs Speaks SMTP
124@chapter Emacs Speaks SMTP
125
126 Emacs includes a package for sending your mail to a SMTP server and
127have it take care of delivering it to the final destination, rather
128than letting the MTA on your local system take care of it. This can
129be useful if you don't have a MTA set up on your host, or if your
130machine is often disconnected from the internet.
131
132 Sending mail via SMTP requires configuring your mail user agent
9f26dc24
GM
133(@pxref{Mail Methods,,,emacs}) to use the SMTP library. If you
134have not configured anything, then in Emacs 24.1 and later the first
135time you try to send a mail Emacs will ask how you want to send
136mail. To use this library, answer @samp{smtp} when prompted. Emacs
137then asks for the name of the SMTP server.
138
139 If you prefer, or if you are using a non-standard mail user agent,
140you can configure this yourself. The normal way to do this is to set
141the variable @code{send-mail-function} (@pxref{Mail
142Sending,,,emacs}) to the value you want to use. To use this library:
143
144@smallexample
4009494e 145(setq send-mail-function 'smtpmail-send-it)
9f26dc24
GM
146@end smallexample
147
148@noindent
149The default value for this variable is @code{sendmail-query-once},
150which interactively asks how you want to send mail.
151
152Your mail user agent might use a different variable for this purpose.
153It should inherit from @code{send-mail-function}, but if it does not,
154or if you prefer, you can set that variable directly. Consult your
155mail user agent's documentation for more details. For example,
156(@pxref{Mail Variables,,,message}).
4009494e
GM
157
158 Before using SMTP you must find out the hostname of the SMTP server
9f26dc24
GM
159to use. Your system administrator or mail service provider should
160supply this information. Often it is some variant of the server you
161receive mail from. If your email address is
162@samp{yourname@@example.com}, then the name of the SMTP server is
163may be something like @samp{smtp.example.com}.
4009494e
GM
164
165@table @code
166@item smtpmail-smtp-server
167@vindex smtpmail-smtp-server
168@vindex SMTPSERVER
169 The variable @code{smtpmail-smtp-server} controls the hostname of
170the server to use. It is a string with an IP address or hostname. It
171defaults to the contents of the @env{SMTPSERVER} environment
172variable, or, if empty, the contents of
173@code{smtpmail-default-smtp-server}.
174
175@item smtpmail-default-smtp-server
176@vindex smtpmail-default-smtp-server
177 The variable @code{smtpmail-default-smtp-server} controls the
178default hostname of the server to use. It is a string with an IP
179address or hostname. It must be set before the SMTP library is
180loaded. It has no effect if set after the SMTP library has been
181loaded, or if @code{smtpmail-smtp-server} is defined. It is usually
182set by system administrators in a site wide initialization file.
183@end table
184
185The following example illustrates what you could put in
186@file{~/.emacs} to set the SMTP server name.
187
188@example
189;; Send mail using SMTP via mail.example.org.
190(setq smtpmail-smtp-server "mail.example.org")
191@end example
192
193@cindex Mail Submission
194SMTP is normally used on the registered ``smtp'' TCP service port 25.
195Some environments use SMTP in ``Mail Submission'' mode, which uses
196port 587. Using other ports is not uncommon, either for security by
197obscurity purposes, port forwarding, or otherwise.
198
199@table @code
200@item smtpmail-smtp-service
201@vindex smtpmail-smtp-service
202 The variable @code{smtpmail-smtp-service} controls the port on the
203server to contact. It is either a string, in which case it will be
204translated into an integer using system calls, or an integer.
205@end table
206
207The following example illustrates what you could put in
208@file{~/.emacs} to set the SMTP service port.
209
210@example
211;; Send mail using SMTP on the mail submission port 587.
212(setq smtpmail-smtp-service 587)
213@end example
214
215@node Authentication
216@chapter Authentication
217
9f26dc24
GM
218@cindex password
219@cindex user name
220Most SMTP servers require clients to authenticate themselves before
221they are allowed to send mail. Authentication usually involves
1df7defd 222supplying a user name and password.
9f26dc24
GM
223
224If you have not configured anything, then the first time you try to
225send mail via a server, Emacs (version 24.1 and later) prompts you
226for the user name and password to use, and then offers to save the
227information. By default, Emacs stores authentication information in
228a file @file{~/.authinfo}.
229
230@cindex authinfo
231The basic format of the @file{~/.authinfo} file is one line for each
232set of credentials. Each line consists of pairs of variables and
233values. A simple example would be:
234
235@smallexample
236machine mail.example.org port 25 login myuser password mypassword
237@end smallexample
238
239@noindent
240This specifies that when using the SMTP server called @samp{mail.example.org}
241on port 25, Emacs should send the user name @samp{myuser} and the
242password @samp{mypassword}. Either or both of the login and password
243fields may be absent, in which case Emacs prompts for the information
244when you try to send mail. (This replaces the old
245@code{smtpmail-auth-credentials} variable used prior to Emacs 24.1.)
246
247@vindex smtpmail-smtp-user
248 When the SMTP library connects to a host on a certain port, it
249searches the @file{~/.authinfo} file for a matching entry. If an
250entry is found, the authentication process is invoked and the
251credentials are used. If the variable @code{smtpmail-smtp-user} is
252set to a non-@code{nil} value, then only entries for that user are
253considered. For more information on the @file{~/.authinfo}
254file, @pxref{Top,,auth-source, auth, Emacs auth-source Library}.
255
4009494e
GM
256@cindex SASL
257@cindex CRAM-MD5
9f26dc24 258@cindex PLAIN
4009494e 259@cindex LOGIN
9f26dc24
GM
260The process by which the SMTP library authenticates you to the server
261is known as ``Simple Authentication and Security Layer'' (SASL).
262There are various SASL mechanisms, and this library supports three of
1df7defd 263them: CRAM-MD5, PLAIN, and LOGIN@. It tries each of them, in that order,
9f26dc24
GM
264until one succeeds. The first uses a form of encryption to obscure
265your password, while the other two do not.
266
267
268@node Encryption
269@chapter Encryption
270
4009494e
GM
271@cindex STARTTLS
272@cindex TLS
273@cindex SSL
9f26dc24
GM
274For greater security, you can encrypt your connection to the SMTP
275server. If this is to work, both Emacs and the server must support it.
276
277The SMTP library supports the ``Transport Layer Security'' (TLS), and
278the older ``Secure Sockets Layer'' (SSL) encryption mechanisms.
279It also supports STARTTLS, which is a variant of TLS in which the
280initial connection to the server is made in plain text, requesting a
281switch to an encrypted channel for the rest of the process.
282
283@vindex smtpmail-stream-type
284The variable @code{smtpmail-stream-type} controls what form of
285connection the SMTP library uses. The default value is @code{nil},
286which means to use a plain connection, but try to switch to a STARTTLS
287encrypted connection if the server supports it. Other possible values
288are: @code{starttls} - insist on STARTTLS; @code{ssl} - use TLS/SSL;
289and @code{plain} - no encryption.
290
291Use of any form of TLS/SSL requires support in Emacs. You can either
292use the built-in support (in Emacs 24.1 and later), or the
293@file{starttls.el} Lisp library. The built-in support uses the GnuTLS
294@footnote{@url{http://www.gnu.org/software/gnutls/}} library.
295If your Emacs has GnuTLS support built-in, the function
296@code{gnutls-available-p} is defined and returns non-@code{nil}.
297Otherwise, you must use the @file{starttls.el} library (see that file for
298more information on customization options, etc.). The Lisp library
299requires one of the following external tools to be installed:
4009494e
GM
300
301@enumerate
302@item
9f26dc24 303The GnuTLS command line tool @samp{gnutls-cli}, which you can get from
4009494e 304@url{http://www.gnu.org/software/gnutls/}. This is the recommended
9f26dc24 305tool, mainly because it can verify server certificates.
4009494e
GM
306
307@item
9f26dc24 308The @samp{starttls} external program, which you can get from
4009494e
GM
309@file{starttls-*.tar.gz} from @uref{ftp://ftp.opaopa.org/pub/elisp/}.
310@end enumerate
311
9f26dc24
GM
312@cindex certificates
313@cindex keys
314The SMTP server may also request that you verify your identity by
315sending a certificate and the associated encryption key to the server.
316If you need to do this, you can use an @file{~/.authinfo} entry like this:
4009494e 317
9f26dc24
GM
318@smallexample
319machine mail.example.org port 25 key "~/.my_smtp_tls.key" cert "~/.my_smtp_tls.cert"
320@end smallexample
4009494e 321
9f26dc24
GM
322@noindent
323(This replaces the old @code{smtpmail-starttls-credentials} variable used
324prior to Emacs 24.1.)
4009494e 325
4009494e
GM
326
327@node Queued delivery
328@chapter Queued delivery
329
330@cindex Dialup connection
331If you connect to the internet via a dialup connection, or for some
332other reason don't have permanent internet connection, sending mail
333will fail when you are not connected. The SMTP library implements
334queued delivery, and the following variable control its behavior.
335
336@table @code
337@item smtpmail-queue-mail
338@vindex smtpmail-queue-mail
339 The variable @code{smtpmail-queue-mail} controls whether a simple
340off line mail sender is active. This variable is a boolean, and
341defaults to @code{nil} (disabled). If this is non-@code{nil}, mail is
342not sent immediately but rather queued in the directory
343@code{smtpmail-queue-dir} and can be later sent manually by invoking
344@code{smtpmail-send-queued-mail} (typically when you connect to the
345internet).
346
347@item smtpmail-queue-dir
348@vindex smtpmail-queue-dir
349 The variable @code{smtpmail-queue-dir} specifies the name of the
350directory to hold queued messages. It defaults to
351@file{~/Mail/queued-mail/}.
352@end table
353
354@findex smtpmail-send-queued-mail
355 The function @code{smtpmail-send-queued-mail} can be used to send
356any queued mail when @code{smtpmail-queue-mail} is enabled. It is
357typically invoked interactively with @kbd{M-x
358smtpmail-send-queued-mail RET} when you are connected to the internet.
359
360@node Server workarounds
361@chapter Server workarounds
362
363Some SMTP servers have special requirements. The following variables
364implement support for common requirements.
365
366@table @code
367
368@item smtpmail-local-domain
369@vindex smtpmail-local-domain
370 The variable @code{smtpmail-local-domain} controls the hostname sent
371in the first @code{EHLO} or @code{HELO} command sent to the server.
372It should only be set if the @code{system-name} function returns a
373name that isn't accepted by the server. Do not set this variable
374unless your server complains.
375
376@item smtpmail-sendto-domain
377@vindex smtpmail-sendto-domain
378 The variable @code{smtpmail-sendto-domain} makes the SMTP library
379add @samp{@@} and the specified value to recipients specified in the
380message when they are sent using the @code{RCPT TO} command. Some
381configurations of sendmail requires this behavior. Don't bother to
382set this unless you have get an error like:
383
384@example
b1fbbb32 385 Sending failed; SMTP protocol error
4009494e
GM
386@end example
387
388when sending mail, and the debug buffer (@pxref{Debugging})) contains
389an error such as:
390
391@example
b1fbbb32
GM
392 RCPT TO: @var{someone}
393 501 @var{someone}: recipient address must contain a domain
4009494e
GM
394@end example
395
396@end table
397
398
399@node Debugging
400@chapter Debugging
401
402Sometimes delivery fails, often with the generic error message
403@samp{Sending failed; SMTP protocol error}. Enabling one or both of
404the following variables and inspecting a trace buffer will often give
405clues to the reason for the error.
406
407@table @code
408
409@item smtpmail-debug-info
410@vindex smtpmail-debug-info
411 The variable @code{smtpmail-debug-info} controls whether to print
412the SMTP protocol exchange in the minibuffer, and retain the entire
413exchange in a buffer @samp{*trace of SMTP session to @var{server}*},
414where @var{server} is the name of the mail server to which you send
415mail.
416
417@item smtpmail-debug-verb
418@vindex smtpmail-debug-verb
419 The variable @code{smtpmail-debug-verb} controls whether to send the
420@code{VERB} token to the server. The @code{VERB} server instructs the
421server to be more verbose, and often also to attempt final delivery
422while your SMTP session is still running. It is usually only useful
423together with @code{smtpmail-debug-info}. Note that this may cause
424mail delivery to take considerable time if the final destination
425cannot accept mail.
426
427@end table
428
429@node GNU Free Documentation License
430@chapter GNU Free Documentation License
431@include doclicense.texi
432
433@node Index
434@chapter Index
435
436@section Concept Index
437
438@printindex cp
439
440@section Function and Variable Index
441
442@printindex fn
443
4009494e 444@bye