File: fetchmail.html

package info (click to toggle)
lg-issue45 1-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,460 kB
  • ctags: 159
  • sloc: makefile: 36; sh: 4
file content (155 lines) | stat: -rw-r--r-- 8,325 bytes parent folder | download | duplicates (3)
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
<!--startcut ==========================================================-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<title>Mail for the Home Network--Fetchmail LG #45</title>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
ALINK="#FF0000">
<!--endcut ============================================================-->

<H4>
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>

<P> <HR> <P> 
<!--===================================================================-->

<center>
<H4><font color="maroon">Mail for the Home Network</font></H4>
<H1><font color="maroon">Fetcahmail</font></H1>
<H4>By <a href="mailto:jpollman@bigfoot.com">JC Pollman</a>
and <a href="mailto:bill.mote@bigfoot.com">Bill Mote</a></H4></center>
</center>
<P> <HR> <P>  

<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <meta name="Author" content="JC Pollman">
   <meta name="GENERATOR" content="Mozilla/4.61 [en] (X11; I; Linux 2.2.11 i686) [Netscape]">
   <title>Fetchmail Setup</title>
</head>
<body>

<center><b><font size=+1>Fetchmail</font></b></center>

<p>Fetchmail will get mail from your email on the net (your ISP account
and wherever else you have an email account) and pass the mail off to procmail
running on your mail server to put it in your mail account on your server.
It can handle a wide variety of mail servers including POP3 and IMAP, but
it can not handle an Exchange Server.
<p>Although fetchmail can be configured to handle quite a variety of chores,
we will keep it simple here. For each user that has an email account on
the internet create a file: ~/.fetchmailrc&nbsp;&nbsp; For user jpollman
on our server, the file /home/jpollman/.fetchmailrc looks like this:
<p><tt>poll www.deniz.com with proto POP3</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; user "jpollman" there with
password "mypassword" is jpollman here</tt>
<p>Explaining each part:
<br>&nbsp;&nbsp;&nbsp; <b>poll www.deniz.com</b>: contact www.deniz.com
which is my ISP's pop3 server.
<br>&nbsp;&nbsp;&nbsp; <b>with proto POP3:</b> use the pop3 protocol to
get the mail.
<br>&nbsp;&nbsp;&nbsp; <b>user "jpollman" there:</b> my login name for
email on my ISP.
<br>&nbsp;&nbsp;&nbsp; <b>with password "mypassword": </b>this is my password
to my ISP.
<br>&nbsp;&nbsp;&nbsp; <b>is jpollman here:</b> jpollman is the user on
our home mail server.
<p>Put a .fetchmailrc file in the home directory of each user that needs
to get mail from the internet.&nbsp; Note: each .fetchmail will be a little
different because everyone has a different email address on the internet.
Also, fetchmail is very particular about permissions and ownership - which
is a good thing as email passwords need to be kept private.&nbsp; To make
sure .fetchmailrc is correct, using the example above for jpollman:
<blockquote><i>chown jpollman /home/jpollman/.fetchmailrc [Enter]</i>
<br><i>chmod 700 /home/jpollman/.fetchmailrc [Enter]</i></blockquote>
If a user has more than one account on the internet, just add additional
lines starting with: poll.
<p>We could have set fetchmail to run as a daemon and poll the ISP every
so often, but fetchmail will cause diald to call out if we are not connected.
Instead we have a simple script, I call it: getmail, that is called both
by <a href="#cron">cron</a> and by <a href="#ipup">ip-up.local</a> - see
below for examples.&nbsp; Here it is:
<p><tt>#!/bin/sh</tt>
<p><tt>if [ -f /var/lock/LCK..ttyS3 ]; then</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; su jpollman -c fetchmail</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; su bmote -c fetchmail</tt>
<br><tt>fi</tt>
<p>When it runs, it first checks to see if we are connected (diald puts
a file called LCK..ttyS3 in my /var/lock directory when it is connected,
and removes it when it disconnects.)&nbsp; Note: you may have set diald
up differently than we did, or may be using pppd daemon, or using a different
com port, so the lock file may have a different name. This script exits
if the lock file is not there.&nbsp; If we are connected, the script will
use su to become jpollman and executes the fetchmail program. The -c means;
run the following command. After fetchmail is has gotten jpollman's mail,
the script becomes bmote via su and runs fetchmail to get his mail. Note:
jpollman and bmote are user names on our server - not the names for their
ISP email accounts.
<p><a NAME="cron"></a><b>Cron:</b> here is a really quick, down-n-dirty,
tutorial on cron. Crond is the daemon that is started when your machine
boots, and so, is always running in the background. It reads the crontab
files every minute to see if anything needs to run. You need to create
a crontab for user "root". To do this, as root, type:
<blockquote><i>crontab crontab [Enter]</i></blockquote>
Root now has his own crontab file - which is identical to the system's
crontab file. To edit root's crontab, type
<blockquote><i>crontab -e [Enter]</i></blockquote>
Leave all the header line alone and delete the program lines. When you
are done, it should look something like this:
<blockquote><tt>SHELL=/bin/bash</tt>
<br><tt>PATH=/sbin:/bin:/usr/sbin:/usr/bin</tt>
<br><tt>HOME=/</tt>
<br><tt>MAILTO="root"</tt></blockquote>
To make cron run a program, add a line with 6 fields: the first five are
the time fields and the six field is the program. As an example:
<blockquote><tt>0 1 * * * getmail</tt></blockquote>
The time fields are broken down this way:
<p><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The time and date fields are:</tt>
<p><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
field&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; allowed values</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-----&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --------------</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
minute&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0-59</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
hour&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0-23</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
day of month&nbsp;&nbsp; 0-31</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
month&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0-12 (or names,
see below)</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
day of week&nbsp;&nbsp;&nbsp; 0-7 (0 or 7 is Sun, or use names)</tt>
<p><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A&nbsp; field&nbsp; may&nbsp;
be an asterisk (*), which always stands for</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ``first-last''.</tt>
<p><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ranges of numbers are allowed.&nbsp;&nbsp;
Ranges&nbsp; are&nbsp; two&nbsp; numbers</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; separated&nbsp; with&nbsp;
a&nbsp; hyphen.&nbsp; The specified range is inclu-</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sive.&nbsp; For example, 8-11
for an ``hours'' entry&nbsp; specifies</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; execution at hours 8, 9, 10
and 11.</tt>
<p>So, in the above example (<tt>0 1 * * * getmail</tt>) getmail will run
at 1 o'clock in the morning everyday. I would prefer to have it run every
5 minutes, so my crontab entry looks like this:
<blockquote><tt>0-59/12 * * * * /usr/local/bin/getmail</tt></blockquote>
To find out more about the crontab file, type:
<blockquote><i>man 5 crontab [Enter]</i></blockquote>
<a NAME="ipup"></a><b>ip-up.local:</b> to have the script run every time
you connect, just add it to your /etc/ppp/ip-up.local (or ip-up file if
that is all you have). To add it, just type it in as a single line with
full path. Mine looks like this:
<blockquote><tt>/usr/local/bin/getmail</tt></blockquote>


<!--===================================================================-->
<P> <hr> <P> 
<center><H5>Copyright &copy; 1999, JC Pollman and Bill Mote <BR> 
Published in Issue 45 of <i>Linux Gazette</i>, September 1999</H5></center>

<!--===================================================================-->