source: INSTALL @ 75:b0c986930d8f

Revision 75:b0c986930d8f, 13.7 KB checked in by tonio, 10 months ago (diff)

Some corrections before releasing.

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