source: INSTALL @ 110:b9ddff240764

Revision 110:b9ddff240764, 14.1 KB checked in by tonio, 6 months ago (diff)

Doc update

Line 
1Installation
2============
3
4Requirements
5------------
6
7- Python version 2.5+
8- Django version 1.0+ (http://docs.djangoproject.com/en/dev/intro/install/#intro-install)
9
10How to install
11--------------
12
13Download Mailng's tarball and extract it::
14
15  tar xzf mailng-<version>.tar.gz
16  mv mailng-<version> mailng
17
18Settings file
19
20  Enter the mailng directory, create a settings.py file (you can use
21  settings-sample.py as a model).
22  Specify database relative informations.
23  You must choose between mysql and postgresql, other types are not supported by
24  major email projects like postfix or dovecot.
25  Create a database with the name you specified in settings.py.
26  you will probably need python database module backend like MySQLdb.
27  Modify TEMPLATE_DIRS.
28
29Initialise the database by running the following command::
30
31  python manage.py syncdb
32
33Create the super admin account (just follow the procedure).
34
35Run the initialisation script. It will insert needed data into the database :
36
37  export PYTHONPATH=$PWD/..
38  DJANGO_SETTINGS_MODULE=mailng.settings ./scripts/populate.py
39
40How to upgrade
41--------------
42
430.6 -> 0.7 : no SQL modifications.
440.5 -> 0.6 : no SQL modifications.
45
46If no modifications have been made to the core SQL schema, juste
47decompress the new tarball at the same location than your current
48installation.
49
50Time zone and language
51----------------------
52
53MailNG is available in english, french and german. You can choose
54which language to use by modifying the LANGUAGE_CODE variable inside
55settings.py::
56
57  LANGUAGE_CODE = 'en-US' # English
58  # or
59  LANGUAGE_CODE = 'fr-FR' # French
60  # or
61  LANGUAGE_CODE = 'de-DE' # German
62
63You can also specify your time zone by modifying the TIME_ZONE
64variable. For example::
65
66  TIME_ZONE = 'Europe/Paris'
67
68Host configuration
69------------------
70
71Before testing Mailng, you must create a group and a user that will be
72used to store mails on the host filesystem. There is only one
73group/user needed because we are in a virtual hosting configuration
74(ie. users with non-UNIX accounts).
75
76For example, create a vmail group::
77
78  groupadd vmail
79
80Then create a vmail user::
81
82  useradd -g vmail -d /var/vmail -m vmail
83
84At last, the system user used to run mailng will need permissions to
85manipulate directories in vmail's homedir. To do that, edit your /etc/sudoers
86file and add the following inside::
87
88  www-data ALL=(vmail) NOPASSWD: ALL
89
90Testing installation
91--------------------
92
93As a typical Django application, Mailng can be tested using a simple web
94server. Just run this command to start it::
95
96  python manage.py runserver
97
98You will be able to play with mailng by looking at
99http://<youraddress>:8000/mailng/admin/.
100
101Tips to link Mailng with postfix
102--------------------------------
103
104First, define following maps on your server (this should work with
105Postfix versions >= 2.2)::
106
107# /etc/postfix/sql-domains.cf
108  user = <user>
109  password = <password>
110  dbname = <database>
111  hosts = 127.0.0.1
112  query = SELECT name FROM admin_domain WHERE name='%s' AND enabled='1'
113
114# /etc/postfix/sql-mailboxes.cf
115  user = <user>
116  password = <password>
117  dbname = <database>
118  hosts = 127.0.0.1
119  query = SELECT path FROM admin_mailbox WHERE full_address = '%s'
120
121# /etc/postfix/sql-aliases.cf
122  user = <user>
123  password = <password>
124  dbname = <database>
125  hosts = 127.0.0.1
126  query = SELECT t2.full_address FROM admin_alias AS t1, admin_mailbox AS t2 WHERE t1.full_address='%s' AND t1.mbox_id=t2.id AND t1.enabled='1'
127
128Then, use the following configuration in your /etc/postfix/main.cf file
129(this is one possible configuration)::
130
131  # Stuff before
132  mailbox_transport = virtual
133  home_mailbox = .maildir/
134  maildrop_destination_recipient_limit = 1
135  virtual_minimum_uid = <vmail user id>
136  virtual_gid_maps = static:<vmail group id>
137  virtual_uid_maps = static:<vmail user id>
138  virtual_mailbox_base = /var/vmail
139
140  relay_domains =
141  virtual_mailbox_domains = mysql:/etc/postfix/sql-domains.cf
142  virtual_mailbox_maps = mysql:/etc/postfix/sql-mailboxes.cf
143  virtual_alias_maps = mysql:/etc/postfix/sql-aliases.cf
144  # Stuff after
145
146NB: Mailng supports both maildir and mbox formats. You can specify
147which format to use by modifying the MAILBOX_TYPE variable located
148inside 'settings.py'.
149
150Tips to activate auto-reply messages in Postifx
151-----------------------------------------------
152
153Since version 0.6, mail users can define an auto-reply message with MailNG.
154
155To activate the extension, edit your settings.py and add the following
156line inside the INSTALLED_APPS variable::
157
158  'mailng.extensions.postfix_autoreply',
159
160Then run the following commands to update MailNG SQL schema and content::
161
162  # python manage.py syncdb
163  # export PYTHONPATH=$PWD/..
164  # DJANGO_SETTINGS_MODULE=mailng.settings ./scripts/upgrade_autoreply.py
165
166To make Postfix understand this feature, you need to update your configuration
167files as follow::
168
169 # /etc/postfix/main.cf
170  transport_maps = mysql:/etc/postfix/maps/sql-transport.cf
171  virtual_alias_maps = mysql:/etc/postfix/maps/sql-aliases.cf
172          mysql:/etc/postfix/maps/sql-autoreplies.cf
173
174 # /etc/postfix/master.cf
175  autoreply unix        -       n       n       -       -       pipe
176            flags= user=nobody argv=<path_to_mailng>/scripts/autoreply $sender $mailbox
177
178Then, create new map files with the following content::
179
180 # /etc/postfix/maps/sql-transport.cf
181  user = <user>
182  password = <password>
183  dbname = <database>
184  hosts = 127.0.0.1
185  query = SELECT method FROM postfix_autoreply_transport WHERE domain='%s'
186
187 # /etc/postfix/maps/sql-autoreplies.cf
188  user = <user>
189  password = <password>
190  dbname = <database>
191  hosts = 127.0.0.1
192  query = SELECT full_address, autoreply_address FROM postfix_autoreply_alias WHERE full_address='%s'
193
194Finally, edit the shell script 'autoreply' located inside the
195'scripts' directory and change the value of BASEDIR. (just put absolute path
196of the directory where mailng is installed)
197
198NB: auto-reply messages are just sent one time per sender for a
199pre-defined time period. By default, this period is equal to 1 day
200(86400s), you can adjust this value by modifying the AUTOREPLY_TIMEOUT
201variable located inside 'settings.py'.
202
203NB: Be sure that both 'autoreply' and 'autoreply.py' scripts (located
204inside the 'scripts' directory) have good permissions (ie. 0755).
205
206Tips to link Mailng with dovecot
207--------------------------------
208
209If you are using 'maildir' format to store mailboxes, add the
210following line inside your main Dovecot config file
211(/etc/dovecot/dovecot.conf)::
212
213  mail_location = maildir:<path_to_mailboxes>/%d/%n/.maildir
214
215If you are using 'mbox' format, put the following::
216 
217  mail_location = mbox:<path_to_mailboxes>/%d/%n/:INBOX=<path_to_mailboxes>/%d/%n/Inbox
218
219To make the authentication work, edit 'dovecot.conf' and add the
220following inside::
221
222  auth default {
223    # ... stuff before
224
225    passdb sql {
226      # Path for SQL configuration file, see /etc/dovecot/dovecot-sql.conf for
227      #  example
228      args = /etc/dovecot/dovecot-sql.conf
229    }
230   
231    userdb sql {
232      # Path for SQL configuration file
233      args = /etc/dovecot/dovecot-sql.conf
234    }
235
236    # ... stuff after
237  }
238
239Be sure to activate only one backend (per type) inside your configuration
240(comment other ones).
241
242Then, edit your /etc/dovecot/dovecot-sql.conf and modify following lines::
243
244  driver = mysql
245  connect = host=<mysqld socket> dbname=<database> user=<user> password=<password>
246  default_pass_scheme = PLAIN-MD5
247  password_query = SELECT full_address AS user, password FROM admin_mailbox WHERE full_address = '%u'
248  user_query = SELECT path AS home, uid, gid FROM admin_mailbox WHERE full_address = '%u'
249
250Enable quotas with Dovecot
251--------------------------
252
253Put the following lines inside your dovecot.conf file::
254
255    protocol imap {
256      mail_plugins = quota quota_imap
257    }
258
259Before continuing, you need to know which quota backend must be user
260(function of mailboxes format)::
261 * 'mbox' : backend=dirsize,
262 * 'maildir' : backend=maildir.
263
264If you use version prior to 1.1, add also the following configuration::
265
266  plugin {
267    # 10 MB default quota limit
268    quota = <backend>:storage=10240
269  }
270
271Then modify the above user_query inside dovecot-sql.conf file like
272that to activate per user quotas::
273
274  user_query = SELECT path AS home, uid, gid, concat('<backend>:storage=', quota / 1024) AS quota FROM admin_mailbox WHERE full_address = '%u'
275
276For version >= 1.1, put the following configuration inside dovecot.conf file::
277
278  plugin {
279    # Default 10M storage limit with an extra 5M limit when saving to Trash.
280    quota = <backend>:User quota
281    quota_rule = *:storage=10M
282    quota_rule2 = Trash:storage=5M
283  }
284
285Then modify the above user_query inside dovecot-sql.conf to activate
286user quotas::
287
288  user_query = SELECT path AS home, uid, gid, concat('*:storage=', quota, 'M') AS quota_rule FROM admin_mailbox WHERE full_address = '%u'
289
290Tips to serve Mailng behind Apache2
291------------------------------------
292
293First, be sure to have apache2 and mod_python installed on your
294server.
295
296Create a new virtualhost in your Apache configuration and put the
297following inside::
298
299  <VirtualHost *:80>
300    <Location "/">
301      SetHandler mod_python
302      PythonHandler django.core.handlers.modpython
303      PythonPath "['<path to directory that contains mailng dir>'] + sys.path"
304      SetEnv DJANGO_SETTINGS_MODULE mailng.settings
305    </Location>
306    Alias "/static" "<path to mailng dir>/static"
307    <Location "/static/">
308      SetHandler None
309    </Location>
310  </VirtualHost>
311
312This is one possible configuration. Note that you will certainly need more
313configuration in order to launch Apache.
314
315Using the amavisd-new quarantine plugin
316---------------------------------------
317
318This plugin allows you and your users to handle amavisd-new SQL
319quarantine. You can consult messages and/or release or delete them.
320
321If you plan to use it, first make sure to have those requirements
322installed on your server::
323
324- mysqldb python module (http://mysql-python.sourceforge.net/)
325- lxml python module (http://codespeak.net/lxml/)
326
327To activate the extension, edit your settings.py and add the following
328line inside the INSTALLED_APPS variable::
329
330  'mailng.extensions.amavis_quarantine',
331
332Just run the following command to update MailNG SQL schema::
333 
334  # python manage.py syncdb
335
336Then, you need to specify where is the database that contains the
337quarantine. Inside settings.py, add a new connection to the
338DB_CONNECTIONS variable like this::
339
340  DB_CONNECTIONS = {
341    "amavis_quarantine" : {"driver"   : "mysql",
342                            "host"     : "<your_host>",
343                            "dbname"   : "<amavis_dbname>",
344                            "login"    : "<user>",
345                            "password" : "<password>"}
346  }
347     
348
349Replace values between <> with yours.
350
351Finally, create a symbolic link to the templates directory inside the
352main templates directory::
353
354  # ln -s <mailng_dir>/extensions/amavis_quarantine/templates \
355        templates/amavis_quarantine
356
357When viewing messages, you can choose to display links (addresses,
358images). In order to display images correctly, you need to create a
359tmp directory under static/ for storing them. For example::
360
361  # mkdir <mailng_dir>/static/tmp
362
363To be able to release messages, first take a look at this page::
364
365http://www.ijs.si/software/amavisd/amavisd-new-docs.html#quar-release
366
367It shows how to configure amavisd-new to listen somewhere for the
368AM.PDP protocol. This protocol is used to send release requests.
369
370Below is an example of a working configuration::
371
372  $interface_policy{'SOCK'} = 'AM.PDP-SOCK';
373  $interface_policy{'9998'} = 'AM.PDP-INET';
374
375  $policy_bank{'AM.PDP-SOCK'} = {
376    protocol => 'AM.PDP',
377    auth_required_release => 0,
378  };
379  $policy_bank{'AM.PDP-INET'} = {
380    protocol => 'AM.PDP',
381    inet_acl => [qw( 127.0.0.1 [::1] )],
382  };
383
384Don't forget to update the inet_acl list if you plan to release from
385the network.
386
387Once amavisd-new is configured, just tell MailNG where it can find the
388"release server" by modifying following variables inside settings.py::
389
390  # "unix" or "inet"
391  AM_PDP_MODE = "inet"
392
393  # "unix" mode only
394  AM_PDP_SOCKET = "/var/amavis/amavisd.sock"
395
396  # "inet" mode only
397  AM_PDP_HOST = "127.0.0.1"
398  AM_PDP_PORT = 9998
399
400Last point, MailNG provides a simple script that periodically purge
401the amavisd-new quarantine database. If you plan to use it, you can
402add the following line inside root's crontab::
403
404  0 0 * * * PYTHONPATH=<mailng_dir/..> \
405    DJANGO_SETTINGS_MODULE=mailng.settings \
406    <mailng_dir>/extensions/amavis_quarantine/cleanup.py
407
408Replace mailng_dir with the installation path of MailNG.
409
410By default, messages older than 14 days are automatically purged. You
411can modify this value by changing the variable MAX_MESSAGES_AGE inside
412settings.py.
413
414Using the statistics plugin
415---------------------------
416
417This plugin allows you to collect various statistics about emails
418traffic on your server. It parses log file to collect information and
419then generates graphics in PNG format.
420
421If you plan to use it, first make sure to have those requirements
422installed on your server::
423
424- rrdtool python binding (http://oss.oetiker.ch/rrdtool/)
425
426To activate the extension, edit your settings.py and add the following
427line inside the INSTALLED_APPS variable::
428
429  'mailng.extensions.stats',
430
431Create a symbolic link to the templates directory inside the main
432templates directory::
433
434  # ln -s <mailng_dir>/extensions/stats/templates \
435       templates/stats
436
437Then, adapt following parameters (still in settings.py) to your
438environnement::
439
440  # Path to mail log file
441  LOGFILE = "/var/log/mail.log"
442
443  # Path to directory where rrd files are stored
444  RRD_ROOTDIR = "/tmp/mailng"
445
446  # Path to directory where png files are stored
447  IMG_ROOTDIR = "<mailng_dir>/static/graphs"
448
449Make sure the directories that will contain those files exist. If not,
450create them before going further. For example (according to previous
451parameters)::
452
453  $ mkdir /tmp/mailng
454  $ mkdir <mailng_dir>/static/graphs
455
456To finish, you need to collect information periodically in order to
457feed rrd files. To do so, just add the following lines into root's
458crontab::
459
460  */5 * * * * PYTHONPATH=<mailng_dir/..> DJANGO_SETTINGS_MODULE=mailng.settings <mailng_dir>/extensions/stats/logparser.py
461
462Replace mailng_dir with the installation path of MailNG.
463
464Graphics are automatically created after each new parsing.
Note: See TracBrowser for help on using the repository browser.