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