Virtual Users With Postfix, PostfixAdmin, Courier, Mailscanner, ClamAV On CentOS - Page 5

Postfix Admin Tweaking

To create the Maildirs on the disk you will need some commands like, we will be doing this automatically by tweaking the Postfix Admin.

Here are some examples to do it manually.

Create the maildir structure:

maildirmake /opt/mail/

Create the softquota maildirsize file in the maildir. (If this file isn't present, no quotas will be enforced.)

maildirmake -q 20971520S /opt/mail/

maildirmake -q N: this option set the quota size (N expressed as bytes, in our case 20971520S = 20MB [default quota in db structure])

Notice the S at the end of the bytes.

chmod g-r,o-r /opt/mail/
chown -R vmail.vmail /opt/mail/

Postfix Admin Tweaking

We need to tweak Postfix Admin so that it can work with Maildrop. Here for we needed 2 extra scripts.

vi /usr/sbin/

set -e
if [ ! -d $mail_home/$1 ] ; then
        mkdir $mail_home/$1
        chown -R vmail:vmail $mail_home/$1
        chmod -R 700 $mail_home/$1
        #echo "$mail_home/$1 CREATED"
if [ -d $mail_home/$1 ] ; then
        cd "$mail_home/$1"
        maildirmake $2
        #echo "$mail_home/$1/$2 CREATED"
        maildirmake -q "$3S" $2
        #echo "$3S $2 QUOTA CREATED"
        chown -R vmail:vmail $mail_home/$1/$2
        chmod -R 700 $mail_home/$1/$2

This script we will use for automatically creating a mailbox with a certain quota. We also need a script for deleting unwanted mailboxes.

vi /usr/sbin/

# vi /usr/sbin/
set -e
if [ -d $mail_home/$1/$2 ] ; then
        rm -Rf  mkdir $mail_home/$1/$2
        #echo "$mail_home/$1/$2 DELETED"

We want to execute these scripts through apache.

vi /etc/sudoers

apache your_hostname = NOPASSWD: /usr/sbin/

Next we will tweak Postfix Admin. Change both create_mailbox.php in the main and admin folder.

system("sudo /usr/sbin/ ".$fDomain." ".$fUsername. " ". $quota);
db_log ($SESSID_USERNAME, $fDomain, "create mailbox","$fUsername");

Change both delete.php in the main and admin folder.

db_query ("DELETE FROM vacation WHERE email='$fDelete' AND domain='$fDomain'");
system("sudo /usr/sbin/ ".$domain.” “.$user);
db_log ($SESSID_USERNAME, $fDomain, "delete mailbox", $fDelete);

And your Postfix Admin now can make the mailbox directories with quota and remove them.


Vacation Install

You need to have the following installed to be able to use Virtual Vacation.
  • Perl5
  • Perl DBI
  • Perl DBD::mysql


yum install perl perl-DBI perl-DBD-MySQL

Virtual Vacation is done with a local shell account that can receive email. The email is then handled by a Perl script which sends the vacation message back to the sender.

Create a dedicated local user account called vacation. This user handles all potentially dangerous mail content - that is why it should be a separate account.

useradd –d /var/spool/vacation -s /sbin/nologin vacation

Do not use nobody, and most certainly do not use root or postfix. The user will never log in, and can be given a * password and non-existent shell and home directory.

This should look like this:

cat /etc/passwd

 vacation:*:65501:65501::0:0:Virtual Vacation:/nonexistent:/sbin/nologin 

Create a directory, for example /var/spool/vacation, that is accessible only to the vacation user. This is where the vacation script is supposed to store its temporary files.

mkdir /var/spool/vacation

Copy the vacation perl from your VACATION directory in Postfix Admin. Get the latest version (Version 3.2) of from the subversion repository.

cp /var/spool/vacation/

chown -R vacation:vacation /var/spool/vacation/
chmod 700 /var/spool/vacation/*

Next we need to setup our transport, at the end of add the following:

vi /etc/postfix/

vacation  unix  -       n       n       -       -       pipe
  flags=DRhu user=vacation argv=/var/spool/vacation/ -f ${sender} -- ${recipient}

Tell Postfix to use a transport maps file, so add the following to your Postfix

vi /etc/postfix/

transport_maps = hash:/etc/postfix/transport

Then add the transport definition to the newly created transport file. Obviously, change to your own domain. This can be any arbitrary domain, and it is easiest if you just choose one that will be used for all your domains.

vi /etc/postfix/transport  vacation

Execute postmap /etc/postfix/transport to build the hashed database:

postmap /etc/postfix/transport

Change in your Postfix Admin file:

$CONF['vacation'] = 'YES';
$CONF['vacation_domain'] = '';

Execute postfix restart to complete the change:

/etc/init.d/postfix restart

Share this page:

0 Comment(s)

Add comment

Please register in our forum first to comment.


By: thim