source: INSTALL @ 160:afaf7e4f14e6

Revision 160:afaf7e4f14e6, 14.6 KB checked in by tonio, 3 months ago (diff)

MailNG is now using south for schema and data migrations.

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