Virtual Users With Postfix, PostfixAdmin, Courier, Mailscanner, ClamAV On CentOS - Page 5
On this page
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/testdomain.com/user1
Create the softquota maildirsize file in the maildir. (If this file isn't present, no quotas will be enforced.)
maildirmake -q 20971520S /opt/mail/testdomain.com/user1
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/testdomain.com/user1
chown -R vmail.vmail /opt/mail/testdomain.com/user1
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/maildirmake.sh
#!/bin/bash set -e mail_home="/opt/mail" 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" fi 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 fi
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/maildirdel.sh
# vi /usr/sbin/maildirdel.sh #!/bin/bash set -e mail_home="/opt/mail" if [ -d $mail_home/$1/$2 ] ; then rm -Rf mkdir $mail_home/$1/$2 #echo "$mail_home/$1/$2 DELETED" fi
We want to execute these scripts through apache.
vi /etc/sudoers
apache your_hostname = NOPASSWD: /usr/sbin/maildirmake.sh
Next we will tweak Postfix Admin. Change both create_mailbox.php in the main and admin folder.
system("sudo /usr/sbin/maildirmake.sh ".$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'"); $userarray=explode("@",$fDelete); $user=$userarray[0]; $domain=$userarray[1]; system("sudo /usr/sbin/maildirdel.sh ".$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
Else
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 vacation.pl from the subversion repository. http://dev.high5.net/trac/wiki
cp vacation.pl /var/spool/vacation/vacation.pl
chown -R vacation:vacation /var/spool/vacation/
chmod 700 /var/spool/vacation/*
vi /etc/postfix/master.cf
# # VIRTUAL VACATION # vacation unix - n n - - pipe flags=DRhu user=vacation argv=/var/spool/vacation/vacation.pl -f ${sender} -- ${recipient}
Tell Postfix to use a transport maps file, so add the following to your Postfix main.cf:
vi /etc/postfix/main.cf
transport_maps = hash:/etc/postfix/transport
Then add the transport definition to the newly created transport file. Obviously, change yourdomain.com 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
autoreply.yourdomain.com vacation
Execute postmap /etc/postfix/transport to build the hashed database:
postmap /etc/postfix/transport
Change in your Postfix Admin config.inc.php file:
$CONF['vacation'] = 'YES'; $CONF['vacation_domain'] = 'autoreply.yourdomain.com';
Execute postfix restart to complete the change:
/etc/init.d/postfix restart