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