]> Pileus Git - ~andy/fetchmail/blob - fetchmail.man
Give up on POP3 UIDs, they're a dead loss.
[~andy/fetchmail] / fetchmail.man
1 .\" Copyright 1993-95 by Carl Harris, Jr. Copyright 1996 by Eric S. Raymond
2 .\" All rights reserved.
3 .\" For license terms, see the file COPYING in this directory.
4 .TH fetchmail LOCAL
5 .SH NAME
6 fetchmail \- retrieve mail from a mailserver using POP2, POP3, APOP, or IMAP
7 .SH SYNOPSIS
8 .B fetchmail
9 [\fI options \fR] \fI [server-host...]\fR
10 .SH DESCRIPTION
11 .I fetchmail
12 is a batch mail retrieval utility intended to be used over on-demand
13 TCP/IP links (such as SLIP or PPP connections).  It fetches mail from
14 remote mail servers and forwards it to your local (client) machine's
15 delivery system, where it can then be be read by normal mail user
16 agents such as \fIelm\fR(1) or \fIMail\fR(1).
17 .PP
18 The
19 .I fetchmail
20 program can gather mail from servers supporting POP2 (as specified in RFC
21 937), POP3 (RFC 1725), IMAP2bis (as implemented by the 4.4BSD imapd
22 program), and IMAP4 (RFC1730).  It can use (but does not require) the
23 RPOP and LAST facilities removed from later POP3 versions.
24 .PP
25 The behavior of
26 .I fetchmail
27 is controlled by comand-line options and a run control file,
28 .I ~/.fetchmailrc
29 the syntax of which we describe below.  Command-line options override
30 .I ~/.fetchmailrc
31 declarations.
32 .PP
33 To facilitate the use of
34 .I fetchmail
35 in scripts, pipelines, etc, it returns an appropriate exit code upon 
36 termination -- see EXIT CODES below.
37 .SH OPTIONS
38 Each server name that you specify (following the options on the
39 command line) will be queried.  If you don't specify any servers
40 on the command line, each server in your 
41 .I ~/.fetchmailrc
42 file will be queried.
43 .TP
44 .B \-2
45 Use Post Office Protocol version 2 (POP2).  See also the 
46 .B \--protocol
47 option, below.
48 .TP
49 .B \-3
50 Use Post Office Protocol version 3 (POP3).  See also the
51 .B \--protocol
52 option, below.
53 .TP
54 .B \-a, --all
55 POP3 only.  Retrieve both old (previously retrieved) and new messages from 
56 the mailserver.
57 .TP
58 .B \-S host, --smtphost host
59 Specify an SMTP forwarding host (other than localhost).  Normally
60 fetched mail is delivered by SMTP over a socket to the client machine
61 .I fetchmail
62 is running on (this simulates the way mail would
63 be delivered to the client by a normal Internet TCP/IP connection).
64 With this option you can specify another host to deliver to.
65 .TP
66 .B \-m mda, --mda mda
67 Specify a mail delivery agent to use.  See OUTPUT OPTIONS below for a
68 complete description.
69 .TP
70 .B \-o folder, --local folder
71 Causes retrieved messages to be appended to file named by the folder 
72 argument. See OUTPUT OPTIONS below for a complete description.
73 .TP
74 .B \-c, --stdout
75 Causes retrieved messages to be written to stdout instead of a mail folder.
76 See OUTPUT OPTIONS below for a complete description.  You may not specify
77 both the
78 .B \-c
79 and 
80 .B \-o
81 options on the same command line.
82 .TP
83 .B \-F, --flush
84 POP3/IMAP only.  Delete old (previously retrieved) messages from the mailserver
85 before retrieving new messages.
86 .TP
87 .B \-f pathname, --fetchmailrc pathname
88 Specify an alternate name for the .fetchmailrc run control file.
89 .TP
90 .B \-k, --keep
91 Keep retrieved messages in folder on remote mailserver.  Normally, messages 
92 are deleted from the folder on the mailserver after they have been retrieved
93 (unless 
94 .I fetchmail
95 was compiled with the KEEP_IS_DEFAULT option).  Specifying the 
96 .B keep 
97 option causes retrieved messages to remain in your folder on the mailserver.
98 .TP
99 .B \-K, --kill
100 Delete retrieved messages from the remote mailserver.  If 
101 .I fetchmail
102 is compiled with the KEEP_IS_DEFAULT option, the
103 .B kill
104 option forces retrieved mail to be deleted.
105 .TP
106 .B \-l lines, --limit lines
107 POP3 and IMAP only.  Retrieve no more than the specified number of
108 lines (POP3) or characters (IMAP) of each message body (plus message
109 headers). The
110 .B keep
111 option is implied by the
112 .B limit
113 option -- i.e. messages downloaded with the 
114 .B limit
115 option remain on the remote mailserver.
116 .TP
117 .B \-p, \--protocol proto
118 Specify the protocol to used when communicating with the remote 
119 mailserver.  If no protocol is specified,
120 .I fetchmail
121 will try each of the supported protocols in turn, terminating after
122 any successful attempt.
123 .I proto 
124 may be one of the following:
125 .RS
126 .IP IMAP
127 IMAP2bis, a compatible subset of IMAP4.
128 .IP POP2
129 Post Office Protocol 2
130 .IP POP3
131 Post Office Protocol 3
132 .IP APOP
133 Use POP3 with MD5 authentication.
134 .RE
135 .TP
136 .B \-P, --port
137 The  option permits you to specify a TCP/IP port to connect on.  You
138 will need to specify this in order to use RPOP authentication.  Otherwise
139 this option will seldom be necessary as all the supported protocols have
140 well-established default port numbers.
141 .TP
142 .B \-r folder, --remote folder
143 Causes an alternate mail folder on the mailserver to be retrieved.
144 The syntax of the folder name is server dependent, as is the default
145 behavior when no folder is specified.  Fortunately, most POP2 and IMAP
146 servers have a reasonable default behavior, so use of this option
147 should be limited to fairly specialized applications.  POP3 does not
148 support a folder specification in the protocol.
149 If the
150 .B remote
151 option is used in conjunction with the POP3 protocol, the remote folder 
152 specification is ignored.
153 .TP
154 .B \-s, --silent
155 Silent mode.  Suppresses all progress/status messages that are normally
156 echoed to stderr during a POP connection.  If both the 
157 .B silent
158 and
159 .B verbose
160 options are specified, the 
161 .B verbose
162 option takes precedence.
163 .TP
164 .B \-u name, --username name
165 Specifies the user idenfication to be used when logging-in to the mailserver.
166 The appropriate user identification is both server and user-dependent.  
167 The default is your login name on the machine that is running 
168 .I fetchmail.
169 See USER AUTHENTICATION below for a complete description.
170 .TP
171 .B \-v, --verbose
172 Verbose mode.  All control messages passed between 
173 .I fetchmail
174 and the mailserver are echoed to stderr.  Specifying
175 .B verbose
176 causes normal progress/status messages which would be redundant or meaningless
177 to be modified or omitted.
178 .TP
179 .B \-N, --norewrite
180 Normally,
181 .I fetchmail
182 edits RFC-822 address headers (To, From, Cc, Bcc, and Reply-To) in
183 fetched mail so that any mail IDs local to the server are expanded to
184 full addresses (@ and the POP host name are appended).  This enables 
185 replies on the client to get addressed correctly (otherwise your
186 mailer might think they should be addressed to local users on the
187 client machine).  This option disables the rewrite.
188 .TP
189 .B \-V, --version
190 Displays the version information for your copy of 
191 .I fetchmail.
192 No POP connection is made.
193 Instead, for each server specified, all option information
194 that would be computed if
195 .I fetchmail.
196 were connecting to that server is displayed.
197 .TP
198 .SH USER AUTHENTICATION
199 User authentication in 
200 .I fetchmail
201 is very much like the authentication mechanism of 
202 .I ftp(1).
203 The correct user-id and password depend upon the underlying security
204 system at the mailserver.  
205 .PP
206 If the mailserver is a Unix machine on which you have an ordinary user 
207 account, your regular login name and password are used with 
208 .I fetchmail.
209 If you use the same login name on both the server and the client machines,
210 you needn't worry about specifying a user-id with the 
211 .B \-u
212 option \-\- 
213 the default behavior will use your login name on the client machine as the 
214 user-id on the server machine.  If you use a different login name
215 on the server machine, specify that login name with the
216 .B \-u
217 option.  e.g. if your login name is 'jsmith' on a machine named 'mailgrunt',
218 you would start 
219 .I fetchmail 
220 as follows:
221 .IP
222 fetchmail -u jsmith mailgrunt
223 .PP
224 The default behavior of 
225 .I fetchmail
226 is to prompt you for your mailserver password before the POP connection is
227 established.  This is the safest way to use 
228 .I fetchmail
229 and ensures that your password will not be compromised.  You may also specify
230 your password in your
231 .I ~/.fetchmailrc
232 file.  This is convenient when using 
233 .I fetchmail
234 in daemon mode or with scripts.
235 .PP
236 On mailservers that do not provide ordinary user accounts, your user-id and 
237 password are usually assigned by the server administrator when you apply for 
238 a mailbox on the server.  Contact your server administrator if you don't know 
239 the correct user-id and password for your mailbox account.
240 .PP
241 POP3 versions up to the RFC1225 version supported an alternate
242 authentication mechanism called RPOP intended to remove the security
243 risk inherent in sending unencrypted account passwords across the net
244 (in RFC1460 this facility was replaced with APOP).  If you specify the
245 RPOP protocol and a connection port in the privileged range (1..1024),
246 .I fetchmail will
247 ship your password entry to the mail server as an RPOP id.
248 (Note: you'll need to be running fetchmail setuid root for RPOP to
249 work --
250 .I fetchmail
251 has to bind to a privileged port locally in order for the mail 
252 server to believe it's allowed to bind to a privileged remote port.)
253 .PP
254 RFC1460 introduced APOP authentication.  In this variant of POP3,
255 you register an APOP password on your server host (the program
256 to do this with on the server is probably called \fIpopauth\fR(8)).  You
257 put the same password in your 
258 .I .fetchmailrc
259 file.  Each time 
260 .I fetchmail
261 logs in, it sends a cryptographically secure hash of your password and
262 the server greeting time to the server, which can verify it by
263 checking its authorization database. 
264 .PP
265 .SH OUTPUT OPTIONS
266 The default behavior of 
267 .I fetchmail
268 is to ship mail via SMTP to port 25 on the machine it is running on
269 (localhost), just as though it were being passed in over a normal TCP/IP link.
270 This normally results in the mail being delivered locally via your
271 system's default MDA (Mail Delivery Agent, usually
272 .I /usr/lib/sendmail
273 but your system may use a different MDA).
274 .PP
275 You can force mail to be passed to an MDA directly with the -mda or -m
276 option.  Some possible MDAs are "/usr/lib/sendmail -oem %s",
277 "/usr/formail", and "/usr/bin/deliver %s" (if the MDA string contains
278 %s, that escape will be expanded into your username on the client
279 machine).  This shouldn't be necessary unless for some reason you
280 want to bypass your system's default MDA.
281 .PP
282 Using the 
283 .B \-o
284 option, you can specify a mail folder to which retrieved
285 messages will be appended;
286 .I fetchmail
287 always writes the retrieved messages using Unix mail folder format so
288 the folder will be parsed correctly by Unix mail programs such as
289 .I elm
290 or
291 .I pine. 
292 .PP
293 If you prefer, for example, to have your POP
294 mail from a machine called 'mailgrunt' stored in the 
295 .I mbox
296 file in your home directory, you would start 
297 .I fetchmail
298 as follows:
299 .IP 
300 fetchmail \-o $HOME/mbox mailgrunt
301 .PP
302 Note that the folder specified with
303 .B \-o
304 is write-locked while fetchmail is writing to it,   
305 .PP
306 .I fetchmail
307 can be used in a shell pipeline by using the 
308 .B \-c
309 option.  In this mode, 
310 .I fetchmail
311 writes the retrieved messages to stdout, instead of a mail folder.  This would
312 allow you, for instance, to pass the incoming mail through a filter that
313 discards mail marked as 'Precedence: junk'.  Suppose you've written an AWK
314 script called 'dumpjunk.awk' to implement a junk mail filter.  The appropriate
315 syntax to retrieve your mail from 'mailgrunt', pass it through the filter,
316 and write it to a folder called 'realmail' in your home directory would be:
317
318 .nf
319   fetchmail -c mailgrunt | awk -f dumpjunk.awk >$HOME/realmail
320 .fi
321 .PP
322 The progress/status messages written to stderr when the 
323 .B \-s
324 option has not been specified, do not interfere with the message stream, which 
325 is written to stdout.  You may even use 
326 .B \-v
327 and 
328 .B \-c
329 together without corrupting the message stream.  It is a good idea to use the
330 .B \-k
331 option when using 
332 .B \-c
333 to insure that your messages will not be lost if part of the shell pipeline 
334 does not function incorrectly.  The safest bet would be something like:
335
336 .nf
337   fetchmail -k -c mailgrunt | myfilter >$HOME/filtered.mail
338 .fi
339 .PP
340 followed by
341
342 .nf
343   fetchmail -c mailgrunt > /dev/null
344 .fi
345 .PP
346 when you're sure the messages were correctly processed by 'myfilter'.
347 .PP
348 .SH DAEMON MODE
349 The 
350 .B --daemon
351 or
352 .B -d 
353 option runs 
354 .I fetchmail
355 in daemon mode.  You must specify a numeric argument which is a
356 polling interval in seconds.
357 .PP
358 In daemon mode, 
359 .I fetchmail
360 puts itself in background and runs forever, querying each specified
361 host and then sleeping for the given polling interval.
362 .PP
363 Simply invoking
364 .IP
365 fetchmail -d 900
366 .PP
367 will, therefore, poll the hosts described in your 
368 .I ~/.fetchmailrc
369 file once every fifteen minutes.
370 .PP
371 Only one daemon process is permitted per user; in daemon mode,
372 .I fetchmail
373 makes a per-user lockfile to guarantee this.  The option
374 .B --quit
375 will kill a running daemon process.
376 .PP
377 The
378 .B -L
379 or
380 .B --logfile
381 option allows you to redirect status messages emitted while in daemon
382 mode into a specified logfile (follow the option with the logfile name).
383 This is primarily useful for debugging configurations.
384 .SH THE RUN CONTROL FILE
385 The preferred way to set up fetchmail (and the only way if you want to
386 specify a password) is to write a .fetchmailrc file in your home directory.
387 To protect the security of your passwords, your ~/.fetchmailrc may not have
388 more than u+r,u+w permissions; 
389 .I fetchmail
390 will complain and exit otherwise.
391 .PP
392 Comments begin with a '#' and extend through the end of the line.
393 Otherwise the file consists of a series of server entries.
394 Blank lines between server entries are ignored.
395 Keywords and identifiers are case sensitive.
396 When there is a conflict between the command-line arguments and the
397 arguments in this file, the command-line arguments take precedence.
398 .PP
399 Legal keywords are:
400
401     server
402     protocol (or proto)
403     username (or user)
404     password (or pass)
405     remotefolder (or remote)
406     localfolder (or local)
407     mda
408     smtphost (or smtp)
409     keep
410     flush
411     fetchall
412     rewrite
413     skip
414     nokeep
415     noflush
416     nofetchall
417     norewrite
418     noskip
419     port
420 .PP
421 All these correspond to the obvuious command-line arguments except
422 two: \fBpassword\fR and \fBskip\fR.
423 .PP
424 The \fBpassword\fR option requires a string argument, which is the password
425 to be used with the entry's server.
426 .PP
427 The \fBskip\fR option tells
428 .I fetchmail 
429 not to query this host unless it is explicitly named on the command
430 line.  A host entry with this flag will be skipped when
431 .I fetchmail
432 called with no arguments steps through all hosts in the run control file.
433 (This option allows you to experiment with test entries safely.)
434 .PP
435 Legal protocol identifiers are
436
437     auto (or AUTO)
438     pop2 (or POP2)
439     pop3 (or POP3)
440     imap (or IMAP)
441     apop (or APOP)
442     rpop (or RPOP)
443 .PP
444 Basic format is:
445
446 .nf
447   server SERVERNAME protocol PROTOCOL username NAME password PASSWORD 
448 .fi
449 .PP
450 Example:
451
452 .nf
453   server pop.provider.net protocol pop3 username jsmith password secret1
454 .fi
455 .PP
456 Or, using some abbreviations:
457
458 .nf
459   server pop.provider.net proto pop3 user jsmith password secret1
460 .fi
461 .PP
462 Multiple servers may be listed:
463
464 .nf
465   server pop.provider.net proto pop3 user jsmith pass secret1
466   server other.provider.net proto pop2 user John.Smith pass My^Hat
467 .fi
468 .PP
469 Other possibilities (note use of \ to escape newline -- this is all 
470 one server definition.
471
472 .nf
473   server pop.provider.net       \e
474         proto pop3              \e
475         port 3111               \e
476         user jsmith             \e
477         pass secret1            \e
478         localfolder ~/mbox
479 .fi
480 If you need to include whitespace in a parameter string, enclose the
481 string in double quotes.  Thus:
482
483 .nf
484   server mail.provider.net      \e
485         proto pop3              \e
486         user jsmith             \e
487         pass secret1            \e
488         mda "/bin/mail %s"
489 .fi
490 Finally, you may have an initial server description headed by the keyword
491 `defaults' instead of `server' followed by a name.  Such a record
492 is interpreted as defaults for all quries to use. It may be overwritten
493 by individual server descriptions.  So, you could write:
494
495 .nf
496   defaults                      \e
497         proto pop3              \e
498         user jsmith             \e
499         mda "/bin/mail %s"
500   server pop.provider.net       \e
501         pass secret1            \e
502   server mail.provider.net      \e
503         pass secret2            \e
504 .fi
505 .SH EXIT CODES
506 To facilitate the use of 
507 .I fetchmail
508 in shell scripts and the like, an exit code is returned to give an indication
509 of what occured during a given POP connection.  The exit code can be tested
510 by the script and appropriate action taken.
511 .PP
512 A simple example follows.  This Bourne shell script executes 
513 .I fetchmail
514 and, if some messages were successfully retrieved from a mailserver retrieved
515 from the command line, it starts the 
516 .I mail
517 utility to read those messages.  Otherwise, it prints a brief message, and
518 exits.
519 .EX 0
520 #!/bin/sh
521
522 if fetchmail $1
523 then
524   mail
525 else
526   echo "No mail to read."
527 fi
528 .EE
529 .PP
530 The exit codes returned by 
531 .I fetchmail
532 are as follows:
533 .IP 0
534 One or more messages were successfully retrieved.
535 .IP 1
536 There was no mail awaiting retrieval.
537 .IP 2
538 An error was encountered when attempting to open a socket for the POP 
539 connection.  If you don't know what a socket is, don't worry about it --
540 just treat this as an 'unrecoverable error'.
541 .IP 3
542 The user authentication step failed.  This usually means that a bad 
543 user-id, password, or RPOP id was specified.
544 .IP 4
545 Some sort of fatal protocol error was detected.
546 .IP 5
547 There was a syntax error in the arguments to 
548 .I fetchmail.
549 .IP 6
550 Some kind of I/O woes occurred when writing to the local folder.
551 .IP 7
552 There was an error condition reported by the server (POP3 only).
553 .IP 8
554 Exclusion error.  This means 
555 .I fetchmail
556 either found another copy of itself already running, or failed in such
557 a way that it isn't sure whether another copy is running.
558 .IP 9
559 The 
560 .I fetchmail.
561 run failed while trying to do an SMTP port open or transaction.
562 .IP 10
563 Something totally undefined occured.  This is usually caused by a bug within
564 .I fetchmail.
565 Do let me know if this happens.
566 .PP
567 When
568 .I fetchmail
569 queries more than one host, the returned status is that of the last
570 host queried.
571 .SH AUTHOR
572 .I fetchmail
573 was originated (under the name `popclient') by Carl Harris at Virginia
574 Polytechnic Institute and State University (a.k.a. Virginia Tech).
575 Version 3.0 of popclient was extensively rewritten and improved by
576 Eric S. Raymond <esr@snark.thyrsus.com>. The program's name was
577 then changed to
578 .I fetchmail
579 to reflect both the presence of IMAP support and the symmetry with sendmail
580 created by the new SMTP forwarding default.
581 .PP
582 .SH FILES
583 .TP 5
584 ~/.fetchmailrc
585 default run control file
586 .TP 5
587 ${TMPDIR}/fetchmail-${HOST}-${USER}
588 lock file to help prevent concurrent runs.
589 .SH ENVIRONMENT
590 For correct initialization, 
591 .I fetchmail
592 requires either that both the USER and HOME environment variables are
593 correctly set, or that \fBgetpwuid\fR(3) be able to retrieve a password
594 entry from your user ID.
595 .SH KNOWN PROBLEMS
596 Use of any of the supported protocols other than APOP requires that
597 the program send unencrypted passwords over the TCP/IP connection to
598 the mail server.  This creates a risk that name/password pairs might
599 be snaffled with a packet sniffer or more sophisticated monitoring
600 software.
601 .pp
602 Running more than one concurrent instance of
603 .I fetchmail
604 on the same mailbox may cause messages to be lost or remain unfetched.
605 (This is a design problem of the POP2, POP3 and IMAP2bis protocols.)
606 .PP
607 If, using POP3, you find that messages you've already read on the
608 server are being fetched, blame RFC1725.  That late version pf the
609 POP3 protocol specification ill-advisedly removed the LAST command, and
610 some servers (including the one distributed with at least some
611 versions of SunOS) follow it (you can verify this by invoking
612 .I fetchmail -v
613 and watching the response to LAST early in the query).  The fix is to
614 install an older POP3 server with LAST or switch to an IMAP server.
615 .PP
616 The RPOP support is not yet well tested.
617 .PP
618 Send comments, bug reports, gripes, and the like to Eric S. Raymond
619 <esr@thyrsus.com>.
620 .SH NOTE
621 This program used to be called `popclient' (the name was changed
622 because it supports IMAP now and may well support more remote-fetch
623 protocols such as DMSP in the future).
624 .PP
625 The --password option of previous (popclient) versions has been removed -- it
626 encouraged people to expose passwords in scripts.  Passwords
627 must now be specified either interactively or in your
628 .I ~/.fetchmailrc
629 file.  The short-form -p option now specifies the protocol to use.
630 .PP
631 The reason the password isn't stored encrypted is because this doesn't
632 actually add protection.  Anyone who's acquired permissions to read your
633 fetchmailrc file will be able to run 
634 .I fetchmail
635 as you anyway -- and if it's
636 your password they're after, they'd be able to use the necessary decoder from
637 .I fetchmail
638 itself to get it.  All encryption would do in this context is give a
639 false sense of security to people who don't think very hard.
640 .SH SEE ALSO
641 mail(1), binmail(1), sendmail(8), popd(8), imapd(8)
642 RFC 937, RFC 1081, RFC 1082, RFC 1225, RFC 1460, RFC 1725.