Typo
[linux_from_scratch_hints.git] / OLD / postfix_fetchmail_procmail.txt
blob5510f0d51c06991f462abbd3e4dd911517dcbfb8
1 TITLE:          Postfix + procmail + fetchmail
2 LFS VERSION:    3.1 + lfsbootscript-1.0
3 AUTHOR:         Michenaud Laurent <lmichenaud@free.fr>
5 SYNOPSIS:
6         How to set up postfix - procmail - fetchmail
8 HINT:
9 This hint explains how to set up a mail server on your lfs
10 using postfix, procmail and fetchmail.
12 Requirements :
13 - a dns server => see the bind hint or the djbdns hint.
14 - Berkerley DB
16 Optional :
17 - a working fcron => see the fcrontab hint
20 I - PROCMAIL
21 ============
23 download here : http://www.procmail.org/procmail-3.22.tar.gz
25 $ tar zxvf procmail-3.21.tar.gz
26 $ cd procmail-3.21
27 $ make BASENAME=/usr install
31 II - POSTFIX
32 ============
34 1) Installation
35 ---------------
37 download here : ftp://ftp.porcupine.org/mirrors/postfix-release/official/postfix-1.1.0.tar.gz
39         a) Compilation
40         
41 If db.h is not in /usr/include 
42 or in /usr/include/db, make will failed.
43 To correct, edit makedefs, search for "db.h" and change the paths.
44 or use following commands :
46 sed 's|/usr/include/db.h|/path/to/db.h|' \
47 makedefs > makedefs~ &&
48 mv makedefs~ makedefs
50 Then,
52 $ make
54         b) create a postfix user and the postfix group
56 In /etc/passwd, add :
57 postfix:x:101:101::/dev/null:/bin/false
59 In /etc/group, add :
60 postfix:x:101:
61 postdrop:x:102:
64         d) Modify /var/mail
66 /var/mail is owned by root on a standard lfs so 
67 postfix can't create files inside it. 
68 Change like this :
69         
70 $ chown postfix.postfix /var/mail
73         e) Finish Install
75 # if new fresh install
76 $ make install
77 # or, if upgrade
78 $ make upgrade 
80 if u choose make install, it will ask u about
81 the different directory u want to use.
83 Recommended :
84 install_root : /
85 temp_dir : /tmp
86 config_directory : /etc/postfix
87 daemon_directory : /usr/libexec/postfix
88 command_directory: /usr/sbin
89 queue_directory: /var/spool/postfix
90 sendmail_path: /usr/sbin/sendmail
91 newaliases_path: /usr/bin/newaliases
92 mailq_path: /usr/bin/mailq
93 mail_owner: postfix
94 setgid_group: postdrop
95 manpage_directory: /usr/share/man
96 readme_directory: [no]
98 Then, you have to run :
99 /etc/postfix/post-install create-missing
101 If it cannot find postconf, that's because this script redefines $PATH.
102 Edit it to make it working.
105 $ /etc/postfix/post-install
107 At last, you can copy the html documentation
108         
109 $ cp -rf html /usr/doc/postfix
112 With this new postfix version, i had to edit the 
113 /etc/postfix/master.cf to make postfix working.
114 I've changed the following :
115 set pickup to unpriv
116 set flush and cleanup to private
117 I have the feeling it is not the good solution
118 but it works. Need help for this point.
122 2) The main configuration file : /etc/postfix/main.cf
123 -----------------------------------------------------
125 # Begin of file
127 # Directories information 
128 queue_directory = /var/spool/postfix
129 mail_spool_directory = /var/mail
130 command_directory = /usr/sbin
131 daemon_directory = /usr/libexec/postfix
133 # Owner of processus
134 mail_owner = postfix
136 default_privs = nobody
138 # Hostname
139 myhostname = zarba.zerezo.org
141 # Domain
142 mydomain = zerezo.org
144 # Which address to use to send mail
145 myorigin = $mydomain
147 # domain list from which the machine considers itself
148 # as the destination of the messages
149 mydestination = $myhostname, localhost.$mydomain, $mydomain, mail.$mydomain
151 #inet_interfaces = all
152 inet_interfaces = $myhostname, localhost
154 # which machines should postfix trust
155 #   possible values are class subnet host
156 mynetworks_style = subnet
158 # At the place of mynetworks_style, you can use :
159 # mynetworks = 192.168.0.0, 127.0.0.1
161 # Which ISP to use to deliver the non local mail
162 relayhost = [smtp.laposte.net]
164 # Which protocol to use for local mail
165 default_transport = smtp
167 # Allow to postfix to know which address are local
168 # and which are external
169 transport_maps = hash:/etc/postfix/transport
171 # Alias file to change local address into valid external mail
172 sender_canonical_maps = hash:/etc/postfix/sender_canonical
174 recipient_canonical_maps = hash:/etc/postfix/recipient_canonical
176 # Aliases
177 alias_maps = hash:/etc/postfix/aliases
178 alias_database = hash:/etc/postfix/aliases
180 # Reject unknown users
181 local_recipient_maps = $alias_maps unix:passwd.byname
183 # Which program to use to deliver mail
184 mailbox_command = /usr/bin/procmail
186 # Concurrency processes
187 local_destination_concurrency_limit = 2
188 default_destination_concurrency_limit = 5
190 # Debug
191 debug_peer_level = 1
193 debugger_command =
194          PATH=/usr/bin:/usr/X11R6/bin
195          xxgdb $daemon_directory/$process_name $process_id & sleep 5
197 # Minimum free space on disk to accept the mail
198 queue_minfree = 5000000
200 # maximum size of a mail
201 message_size_limit = 10000000
203 # Send a copy of error message to the postmaster
204 notify_classes = resource,software,bounce,delay,policy
206 # Pause in seconds to do when the message arrival 
207 # rate exceeds the message delivery rate
208 in_flow_delay = 1
210 sendmail_path = /usr/sbin/sendmail
211 newaliases_path = /usr/bin/newaliases
212 mailq_path = /usr/bin/mailq
213 setgid_group = postdrop
214 manpage_directory = /usr/share/man
215 sample_directory = /etc/postfix/sample
216 readme_directory = no
219 # End of file
222 3) alias configuration : /etc/postfix/aliases 
223 ---------------------------------------------
225 It allows you to redirect the mails of a user
226 to another user or severals users.
227 Edit /etc/postfix/aliases
229 Example :
230 root:   zarba:
231 webmaster: zarba:
232 familly: zarba, dad, mum, karine
234 Then, run to update the database file :
236 $ newaliases
239 4) /etc/postfix/recipient_canonical
240 -----------------------------------
242 This allow to transform external addresses into
243 internal addresses.
245 edit /etc/postfix/recipient_canonical
247 # begin of file
248 laurent.michenaud@laposte.net   zarba
249 karine.michenaud@laposte.net    karine
250 laurent.michenaud@wanadoo.fr    zarba
251 # end of file
253 Then, update the database file :
254 $ postmap /etc/postfix/recipient_canonical
257 5) /etc/postfix/sender_canonical
258 --------------------------------
260 This allows to transform your local address
261 into valid external addresses.
262 For example, my domain zarba.zerezo.org is not
263 registered on internet. So, when i send external mails,
264 my address should be change into a valid one.
266 edit /etc/postfix/sender_canonical
268 # begin of file
269 root  laurent.michenaud@yourfai.com
270 karine karine.michenaud@yourfai.com
271 # end of file
273 Then, update the database file :
274 $ postmap /etc/postfix/sender_canonical
278 6) /etc/postfix/transport
279 -------------------------
281 Postfix has to know which mails are local and
282 which are externals.
284 Example :
285 zarba.zerezo.org        local:
286 localhost         local:
288 Update the database file :
289 postmap /etc/postfix/transport
293 7) Postfix administration
294 -------------------------
296         postfix start         : to start the mail server
297         postfix stop         : to stop the mail server
298         postfix reload         : to reload the mail server
299         postfix check         : check the configuration and the permissions
300         postfix flush         : to send the undelivered mail
301         mailq                 : to see mails which have not been delivered
302                         ( you must be root )
303         
306 8) the boot script /etc/rc.d/init.d/postfix
307 -------------------------------------------
309 # be carefull, it uses the new bootscripts-1.0 system
311 #!/bin/sh
313 source /etc/sysconfig/rc
314 source $rc_functions
316 case "$1" in
317         start)
318                 echo -n "Starting the mail server..."
319                 /usr/sbin/postfix start
320                 evaluate_retval
321                 ;;
323         stop)
324                 echo -n "Stopping the mail server..."
325                 /usr/sbin/postfix stop
326                 evaluate_retval
327                 ;;
329         reload)
330                 echo -n "Reloading the mail server..."
331                 /usr/sbin/postfix reload
332                 evaluate_retval
333                 ;;
335         restart)
336                 $0 stop
337                 /usr/bin/sleep 1
338                 $0 start
339                 ;;
341         *)
342                 echo "Usage: $0 {start|stop|reload|restart}"
343                 exit 1
344         ;;
346 esac
347 # End of file
350 $ cd /etc/rc.d/init.d/rc0.d
351 $ ln -s ../init.d/postfix K05postfix
352 $ cd ../rc6.d
353 $ ln -s ../init.d/postfix K05postfix
354 $ cd ../rc3.d
355 $ ln -s ../init.d/postfix S45postfix
356 $ cd ../rc5.d
357 $ ln -s ../init.d/postfix S45postfix
361 III - FETCHMAIL
362 ===============
364 download here : http://www.tuxedo.org/~esr/fetchmail/fetchmail-5.9.6.tar.gz
366         a) installation
368 # You can add --with-ssl option to ./configure if u want( OpenSSL needed ).
370 $ ./configure --prefix=/usr --enable-fallback=procmail --sysconfdir=/etc
371 $ make
372 $ make install
375         b) configuration
376   
377 Edit ~/.fetchmailrc and add your mail accounts.
379 # Begin of file
380 set logfile /var/log/fetchmail.log
381 set no bouncemail
382 set postmaster root
384 poll pop.free.fr :
385         user "isplogin" pass "isppassword" is zarba here ;
386 # End of file
389         c) crontab
390         
391 I've done a script which is run every ten minutes and
392 which gets my mail on my different mail account.
394 My script /root/bin/checkmail :
396 #!/bin/bash
397 if [ -e /var/run/ppp0.pid ]
398 then
399         /opt/network/bin/fetchmail
402 The command in fcrontab :
403 $ fcrontab -u root -e
405 @ 10 touch /root/bin/checkmail -F
408         d) Alternative
410 I used this fetchmail configuration when i had a non permanent connexion.
411 Since i have hot an adsl connexion, i didnot use anymore fcrontab for fetchmail.
412 I let run fetchmail as a daemon.
413 This can be done by adding this line in the file .fetchmailrc :
415 set daemon 600
417 600 is the number of seconds between each mail check.
420 IV - QPOPPER
421 ============
423         qpopper is a pop server. If u have a little network at home and
424 u want to be able to check your mail gathered by fetchmail from another 
425 box, u have to install it.
427 download here :
428 ftp://ftp.qualcomm.com/eudora/servers/unix/popper/qpopper4.0.3.tar.gz
430 Installation
432 ./configure --prefix=/usr --sysconfdir=/etc
434 optional, u can add --with-openssl=/path/to/openssl
436 make &&
438 make install &&
440 Add a service qpopper in xinetd :
442 service pop3
444         socket_type     = stream
445         protocol        = tcp
446         wait            = no
447         user            = root
448         server          = /usr/sbin/popper
449         server_args     = qpopper -s
450         port            = 110
451         only_from       = 192.168.0.0
452         bind            = 192.168.0.51
453         disable         = no
456 restart xinetd.
458 I have restricted qpopper so it is avaible only on
459 my network and not on internet.
462 IV - Final
463 ==========
465         This hint needs to be completed.
466         Good luck.
468 TODO :
469 Amavis integration( virus scanner )
470 LDAP integration