logos

With Andrii Grytsenko


Technical Diary - With Andrii Grytsenko

Dbmail mailbox quota notification script

Here is the script which check quota limits in the dbmail and in case of exceeding, script send mail to user and postmaster.

Get script mail_quota.pl and mail_quota.conf configuration file at first.

To make script work fine two cpan modules should be installed:

cpan -i Mail::Send

and

cpan -i DBD::Pg

This is dbmail table dbmail_users description:

dbmail=# \d dbmail_users
Table "public.dbmail_users"
Column      |            Type             |                              Modifiers
-----------------+-----------------------------+---------------------------------------------------------------------
user_idnr       | bigint                      | not null default nextval('dbmail_user_idnr_seq'::regclass)
userid          | character varying(100)      | not null
passwd          | character varying(34)       | not null
client_idnr     | bigint                      | not null default 0::bigint
maxmail_size    | bigint                      | not null default 0::bigint
curmail_size    | bigint                      | not null default 0::bigint
maxsieve_size   | bigint                      | not null default 0::bigint
cursieve_size   | bigint                      | not null default 0::bigint
encryption_type | character varying(20)       | not null default ''::character varying
last_login      | timestamp without time zone | not null default '1979-11-03 22:05:58'::timestamp without time zone

There is configuration:

cat mail_quota.conf:
user=user
host=localhost
port=5432
dbname=db
password=pass
min_thre=80
max_thre=90
admin_mail=admin@domain.com

No comment in the configuration file is permitted. First 4 lines describe database connection.
min_thre/max_thre – minimum and maximum threshold for notification measure is percent. If minimum threshold will be reached user receive mail about quota exceeding. In case of maximum reaching, mail also will be sent to administrator.

To make checking on regular basis add it into the crontab file.

crontab -l
# m h  dom mon dow   command
59 23 * * *     /path/to/mail_quota.pl /path/to/mail_quota.conf

Below we check mail quota every day at 23.59.

Leave a Reply

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Categories

Translate