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