Minor doc/misc/*.texi direntry fixes.
[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
114f9c96 6Copyright @copyright{} 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
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
23@dircategory Emacs
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
GM
49* Authentication:: Authenticating yourself to the server.
50* Queued delivery:: Sending mail without an internet connection.
51* Server workarounds:: Mail servers with special requirements.
52* Debugging:: Tracking down problems.
4009494e
GM
53* GNU Free Documentation License:: The license for this documentation.
54
55Indices
56
9360256a 57* Index:: Index over variables and functions.
4009494e
GM
58@end menu
59
60@node How Mail Works
61@chapter How Mail Works
62
63@cindex SMTP
64@cindex MTA
65 On the internet, mail is sent from mail host to mail host using the
66simple mail transfer protocol (SMTP). To send and receive mail, you
67must get it from and send it to a mail host. Every mail host runs a
68mail transfer agent (MTA) such as Exim that accepts mails and passes
69them on. The communication between a mail host and other clients does
70not necessarily involve SMTP, however. Here is short overview of what
71is involved.
72
73@cindex MUA
74 The mail program --- also called a mail user agent (MUA) ---
75usually sends outgoing mail to a mail host. When your computer is
76permanently connected to the internet, it might even be a mail host
77itself. In this case, the MUA will pipe mail to the
78@file{/usr/lib/sendmail} application. It will take care of your mail
79and pass it on to the next mail host.
80
81@cindex ISP
82 When you are only connected to the internet from time to time, your
83internet service provider (ISP) has probably told you which mail host
84to use. You must configure your MUA to use that mail host. Since you
85are reading this manual, you probably want to configure Emacs to use
86SMTP to send mail to that mail host. More on that in the next
87section.
88
89@cindex MDA
90 Things are different when reading mail. The mail host responsible
91for your mail keeps it in a file somewhere. The messages get into the
92file by way of a mail delivery agent (MDA) such as procmail. These
93delivery agents often allow you to filter and munge your mails before
94you get to see it. When your computer is that mail host, this file is
95called a spool, and sometimes located in the directory
96@file{/var/spool/mail/}. All your MUA has to do is read mail from the
97spool, then.
98
99@cindex POP3
100@cindex IMAP
101 When your computer is not always connected to the internet, you
102must get the mail from the remote mail host using a protocol such as
103POP3 or IMAP. POP3 essentially downloads all your mail from the mail
104host to your computer. The mail is stored in some file on your
105computer, and again, all your MUA has to do is read mail from the
106spool.
107
108 When you read mail from various machines, downloading mail from the
109mail host to your current machine is not convenient. In that case,
110you will probably want to use the IMAP protocol. Your mail is kept on
111the mail host, and you can read it while you are connected via IMAP to
112the mail host.
113
114@cindex Webmail
115 So how does reading mail via the web work, you ask. In that case,
116the web interface just allows you to remote-control a MUA on the web
117host. Whether the web host is also a mail host, and how all the
118pieces interact is completely irrelevant. You usually cannot use
119Emacs to read mail via the web, unless you use software that parses
120the ever-changing HTML of the web interface.
121
122@node Emacs Speaks SMTP
123@chapter Emacs Speaks SMTP
124
125 Emacs includes a package for sending your mail to a SMTP server and
126have it take care of delivering it to the final destination, rather
127than letting the MTA on your local system take care of it. This can
128be useful if you don't have a MTA set up on your host, or if your
129machine is often disconnected from the internet.
130
131 Sending mail via SMTP requires configuring your mail user agent
132(@pxref{Mail Methods,,,emacs}) to use the SMTP library. How to do
133this should be described for each mail user agent; for the default
134mail user agent the variable @code{send-mail-function} (@pxref{Mail
135Sending,,,emacs}) is used; for the Message and Gnus user agents the
136variable @code{message-send-mail-function} (@pxref{Mail
137Variables,,,message}) is used.
138
139@example
140;; If you use the default mail user agent.
141(setq send-mail-function 'smtpmail-send-it)
142;; If you use Message or Gnus.
143(setq message-send-mail-function 'smtpmail-send-it)
144@end example
145
146 Before using SMTP you must find out the hostname of the SMTP server
147to use. Your system administrator should provide you with this
148information, but often it is the same as the server you receive mail
149from.
150
151@table @code
152@item smtpmail-smtp-server
153@vindex smtpmail-smtp-server
154@vindex SMTPSERVER
155 The variable @code{smtpmail-smtp-server} controls the hostname of
156the server to use. It is a string with an IP address or hostname. It
157defaults to the contents of the @env{SMTPSERVER} environment
158variable, or, if empty, the contents of
159@code{smtpmail-default-smtp-server}.
160
161@item smtpmail-default-smtp-server
162@vindex smtpmail-default-smtp-server
163 The variable @code{smtpmail-default-smtp-server} controls the
164default hostname of the server to use. It is a string with an IP
165address or hostname. It must be set before the SMTP library is
166loaded. It has no effect if set after the SMTP library has been
167loaded, or if @code{smtpmail-smtp-server} is defined. It is usually
168set by system administrators in a site wide initialization file.
169@end table
170
171The following example illustrates what you could put in
172@file{~/.emacs} to set the SMTP server name.
173
174@example
175;; Send mail using SMTP via mail.example.org.
176(setq smtpmail-smtp-server "mail.example.org")
177@end example
178
179@cindex Mail Submission
180SMTP is normally used on the registered ``smtp'' TCP service port 25.
181Some environments use SMTP in ``Mail Submission'' mode, which uses
182port 587. Using other ports is not uncommon, either for security by
183obscurity purposes, port forwarding, or otherwise.
184
185@table @code
186@item smtpmail-smtp-service
187@vindex smtpmail-smtp-service
188 The variable @code{smtpmail-smtp-service} controls the port on the
189server to contact. It is either a string, in which case it will be
190translated into an integer using system calls, or an integer.
191@end table
192
193The following example illustrates what you could put in
194@file{~/.emacs} to set the SMTP service port.
195
196@example
197;; Send mail using SMTP on the mail submission port 587.
198(setq smtpmail-smtp-service 587)
199@end example
200
201@node Authentication
202@chapter Authentication
203
204@cindex SASL
205@cindex CRAM-MD5
206@cindex LOGIN
207@cindex STARTTLS
208@cindex TLS
209@cindex SSL
210Many environments require SMTP clients to authenticate themselves
211before they are allowed to route mail via a server. The two following
212variables contains the authentication information needed for this.
213
214The first variable, @code{smtpmail-auth-credentials}, instructs the
215SMTP library to use a SASL authentication step, currently only the
216CRAM-MD5 and LOGIN mechanisms are supported and will be selected in
217that order if the server support both.
218
219The second variable, @code{smtpmail-starttls-credentials}, instructs
220the SMTP library to connect to the server using STARTTLS. This means
221the protocol exchange may be integrity protected and confidential by
222using the Transport Layer Security (TLS) protocol, and optionally also
223authentication of the client and server.
224
225TLS is a security protocol that is also known as SSL, although
226strictly speaking, SSL is an older variant of TLS. TLS is backwards
227compatible with SSL. In most mundane situations, the two terms are
228equivalent.
229
230The TLS feature uses the elisp package @file{starttls.el} (see it for
231more information on customization), which in turn require that at
232least one of the following external tools are installed:
233
234@enumerate
235@item
236The GNUTLS command line tool @samp{gnutls-cli}, you can get it from
237@url{http://www.gnu.org/software/gnutls/}. This is the recommended
238tool, mainly because it can verify the server certificates.
239
240@item
241The @samp{starttls} external program, you can get it from
242@file{starttls-*.tar.gz} from @uref{ftp://ftp.opaopa.org/pub/elisp/}.
243@end enumerate
244
245It is not uncommon to use both these mechanisms, e.g., to use STARTTLS
246to achieve integrity and confidentiality and then use SASL for client
247authentication.
248
249@table @code
250@item smtpmail-auth-credentials
251@vindex smtpmail-auth-credentials
252 The variable @code{smtpmail-auth-credentials} contains a list of
253hostname, port, username and password tuples. When the SMTP library
254connects to a host on a certain port, this variable is searched to
255find a matching entry for that hostname and port. If an entry is
256found, the authentication process is invoked and the credentials are
257used.
258
259The hostname field follows the same format as
260@code{smtpmail-smtp-server} (i.e., a string) and the port field the
261same format as @code{smtpmail-smtp-service} (i.e., a string or an
262integer). The username and password fields, which either can be
263@code{nil} to indicate that the user is prompted for the value
264interactively, should be strings with the username and password,
265respectively, information that is normally provided by system
266administrators.
267
268@item smtpmail-starttls-credentials
269@vindex smtpmail-starttls-credentials
270 The variable @code{smtpmail-starttls-credentials} contains a list of
271tuples with hostname, port, name of file containing client key, and
272name of file containing client certificate. The processing is similar
273to the previous variable. The client key and certificate may be
274@code{nil} if you do not wish to use client authentication.
275@end table
276
277The following example illustrates what you could put in
278@file{~/.emacs} to enable both SASL authentication and STARTTLS. The
279server name (@code{smtpmail-smtp-server}) is @var{hostname}, the
280server port (@code{smtpmail-smtp-service}) is @var{port}, and the
281username and password are @var{username} and @var{password}
282respectively.
283
284@example
285;; Authenticate using this username and password against my server.
286(setq smtpmail-auth-credentials
287 '(("@var{hostname}" "@var{port}" "@var{username}" "@var{password}")))
288
289;; Note that if @var{port} is an integer, you must not quote it as a
290;; string. Normally @var{port} should be the integer 25, and the example
291;; become:
292(setq smtpmail-auth-credentials
293 '(("@var{hostname}" 25 "@var{username}" "@var{password}")))
294
295;; Use STARTTLS without authentication against the server.
296(setq smtpmail-starttls-credentials
297 '(("@var{hostname}" "@var{port}" nil nil)))
298@end example
299
300@node Queued delivery
301@chapter Queued delivery
302
303@cindex Dialup connection
304If you connect to the internet via a dialup connection, or for some
305other reason don't have permanent internet connection, sending mail
306will fail when you are not connected. The SMTP library implements
307queued delivery, and the following variable control its behavior.
308
309@table @code
310@item smtpmail-queue-mail
311@vindex smtpmail-queue-mail
312 The variable @code{smtpmail-queue-mail} controls whether a simple
313off line mail sender is active. This variable is a boolean, and
314defaults to @code{nil} (disabled). If this is non-@code{nil}, mail is
315not sent immediately but rather queued in the directory
316@code{smtpmail-queue-dir} and can be later sent manually by invoking
317@code{smtpmail-send-queued-mail} (typically when you connect to the
318internet).
319
320@item smtpmail-queue-dir
321@vindex smtpmail-queue-dir
322 The variable @code{smtpmail-queue-dir} specifies the name of the
323directory to hold queued messages. It defaults to
324@file{~/Mail/queued-mail/}.
325@end table
326
327@findex smtpmail-send-queued-mail
328 The function @code{smtpmail-send-queued-mail} can be used to send
329any queued mail when @code{smtpmail-queue-mail} is enabled. It is
330typically invoked interactively with @kbd{M-x
331smtpmail-send-queued-mail RET} when you are connected to the internet.
332
333@node Server workarounds
334@chapter Server workarounds
335
336Some SMTP servers have special requirements. The following variables
337implement support for common requirements.
338
339@table @code
340
341@item smtpmail-local-domain
342@vindex smtpmail-local-domain
343 The variable @code{smtpmail-local-domain} controls the hostname sent
344in the first @code{EHLO} or @code{HELO} command sent to the server.
345It should only be set if the @code{system-name} function returns a
346name that isn't accepted by the server. Do not set this variable
347unless your server complains.
348
349@item smtpmail-sendto-domain
350@vindex smtpmail-sendto-domain
351 The variable @code{smtpmail-sendto-domain} makes the SMTP library
352add @samp{@@} and the specified value to recipients specified in the
353message when they are sent using the @code{RCPT TO} command. Some
354configurations of sendmail requires this behavior. Don't bother to
355set this unless you have get an error like:
356
357@example
b1fbbb32 358 Sending failed; SMTP protocol error
4009494e
GM
359@end example
360
361when sending mail, and the debug buffer (@pxref{Debugging})) contains
362an error such as:
363
364@example
b1fbbb32
GM
365 RCPT TO: @var{someone}
366 501 @var{someone}: recipient address must contain a domain
4009494e
GM
367@end example
368
369@end table
370
371
372@node Debugging
373@chapter Debugging
374
375Sometimes delivery fails, often with the generic error message
376@samp{Sending failed; SMTP protocol error}. Enabling one or both of
377the following variables and inspecting a trace buffer will often give
378clues to the reason for the error.
379
380@table @code
381
382@item smtpmail-debug-info
383@vindex smtpmail-debug-info
384 The variable @code{smtpmail-debug-info} controls whether to print
385the SMTP protocol exchange in the minibuffer, and retain the entire
386exchange in a buffer @samp{*trace of SMTP session to @var{server}*},
387where @var{server} is the name of the mail server to which you send
388mail.
389
390@item smtpmail-debug-verb
391@vindex smtpmail-debug-verb
392 The variable @code{smtpmail-debug-verb} controls whether to send the
393@code{VERB} token to the server. The @code{VERB} server instructs the
394server to be more verbose, and often also to attempt final delivery
395while your SMTP session is still running. It is usually only useful
396together with @code{smtpmail-debug-info}. Note that this may cause
397mail delivery to take considerable time if the final destination
398cannot accept mail.
399
400@end table
401
402@node GNU Free Documentation License
403@chapter GNU Free Documentation License
404@include doclicense.texi
405
406@node Index
407@chapter Index
408
409@section Concept Index
410
411@printindex cp
412
413@section Function and Variable Index
414
415@printindex fn
416
4009494e
GM
417@bye
418
419@ignore
420 arch-tag: 6316abdf-b366-4562-87a2-f37e8f894b6f
421@end ignore