第二步:(实现web端的收发,以及支持mysql端虚拟用户的收发,密码的修改等)

1.环境配置

yum install httpd mysql mysql-devel mysql-server php php-pecl-Fileinfo php-mcrypt php-devel php-mysql php-common php-mbstring php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc pcre pcre-devel

# vi /etc/httpd/conf/httpd.conf

#增加下面两行

AddType application/x-httpd-php .php

PHPIniDir "/etc/php.ini"

#修改下面四行

DirectoryIndex index.php index.html index.html.var

User vmail

Group vmail

Listen 9999(为了测试方便,端口号未修改)


# vi /var/www/html/index.php

<?php phpinfo();?>

# systemctl start httpd.service

浏览器输入

http://110.110.110.110:9999/即可测试成功


2.配置postfixadmin

# tar -zxvf postfixadmin-2.93.tar.gz -C /var/www/html

# cd /var/www/html

# mv postfixadmin-2.93 postfixadmin

# vi postfixadmin/config.inc.php

$CONF['configured'] = true;

$CONF['setup_password'] = 'afe0c247277cb58f7ccf798da29b0976:8744abeb23a481eb0fc14a8f9286da0827352d02';

$CONF['database_type'] = 'mysql';

$CONF['database_host'] = 'localhost';

$CONF['database_user'] = 'postfix';

$CONF['database_password'] = 'postfix';

$CONF['database_name'] = 'postfix';

$CONF['admin_email'] = 'wc@free.com';

$CONF['encrypt'] = 'dovecot:CRAM-MD5';

$CONF['dovecotpw'] = "/usr/bin/doveadm pw";

$CONF['domain_path'] = 'YES';

$CONF['domain_in_mailbox'] = 'NO';

$CONF['aliases'] = '1000';

$CONF['mailboxes'] = '1000';

$CONF['maxquota'] = '1000';

$CONF['fetchmail'] = 'NO';

$CONF['quota'] = 'YES';

$CONF['used_quotas'] = 'YES';

$CONF['new_quota_table'] = 'YES';


3.配置mysql

systemctl start mariadb.service

mysql

mysql> create database postfix;

mysql> grant all on postfix.* to postfix@'localhost' identified by 'postfix';

mysql> flush privileges;

# mysql -u postfix -p postfix

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| postfix            |

| test               |

+--------------------+

3 rows in set (0.00 sec)

mysql>


4.浏览器验证

# chown -R vmail.vmail postfixadmin/

http://110.110.110.110/postfixadmin/setup.php

如果报错说没有dovecot安装即可

yum install dovecot dovecot-devel dovecot-mysql

http://110.110.110.110/postfixadmin/login.php能登录即可


5.postfxiadmin不能自动创建目录,所以我们得增加自动建立目录的功能

5.1建立创建虚拟邮箱脚本

# vim /usr/local/bin/maildir-creation.sh

#!/bin/bash

#

HOME_DIR="/var/vmail"

USER_NAME="vmail"

GROUP_NAME="vmail"

if [ ! -d ${HOME_DIR}/$1 ] ; then

    mkdir ${HOME_DIR}/$1

    chown -R ${USER_NAME}.${GROUP_NAME} ${HOME_DIR}/$1

fi

mkdir ${HOME_DIR}/$1/$2

chown -R ${USER_NAME}.${GROUP_NAME} ${HOME_DIR}/$1/$2


5.2建立删除虚拟邮箱脚本

# vim /usr/local/bin/maildir-deletion.sh

#!/bin/bash

#

# vmta ALL = NOPASSWD: /usr/local/bin/maildir-deletion.sh

#

if [ $# -ne 2 ] ; then

  exit 127

fi

DOMAIN="$1"

USER="$2"

HOME_DIR="/var/vmail"

USER_DIR="${HOME_DIR}/${DOMAIN}/${USER}"

TRASH_DIR="${HOME_DIR}/deleted-maildirs"

DATE=`date "+%Y%m%d_%H%M%S"`

if [ ! -d "${TRASH_DIR}/${DOMAIN}" ] ; then

    mkdir -p "${TRASH_DIR}/${DOMAIN}"

fi

if [ -d "${USER_DIR}" ] ; then

    mv ${USER_DIR} ${TRASH_DIR}/${DOMAIN}/${USER}-${DATE}

fi


5.3手动建立目录及赋予权限

# mkdir /var/vmail/deleted-maildirs

# chown -R vmail.vmail /var/vmail/deleted-maildirs/

# chmod 750 /usr/local/bin/maildir-*

# chown vmail.vmail /usr/local/bin/maildir-*

#vim /etc/sudoers

#文本最后增加两行

vmail ALL = NOPASSWD: /usr/local/bin/maildir-creation.sh

vmail ALL = NOPASSWD: /usr/local/bin/maildir-deletion.sh

#修改下面一行

#Defaults    requiretty

:wq! #由于这个文件是只读的,所以得强制保存并退出


5.4未找到的内容,参考文献上有,本人并未配置(任然需要测试)

# cd /var/www/html/postfixadmin/

# vim create-mailbox.php

修改create-mailbox.php 文件,229行内容应该是:

db_log ($SESSID_USERNAME, $fDomain, 'create_mailbox', "$fUsername");

在该行前面增加下面一行,

system("sudo /usr/local/bin/maildir-creation.sh $fDomain ".$_POST['fUsername']);

# vim delete.php

修改delete.php 文件,146行内容应该是,

db_log ($SESSID_USERNAME, $fDomain, 'delete_mailbox', $fDelete);

在该行下面增加下面4行,

$userarray=explode("@",$fDelete);

$user=$userarray[0];

$domain=$userarray[1];

system("sudo /usr/local/bin/maildir-deletion.sh $domain $user");


6.


参考:

http://freeloda.blog.51cto.com/2033581/1245492/

http://blog.163.com/qiushuhui1989@126/blog/static/2701108920146279368171/


报错1:浏览器输入http://110.110.110.110/postfixadmin/setup.php报错如下

Error: Smarty template compile directory templates_c is not writable

解决1:目录权限问题,chown -R vmail.vmail postfixadmin执行即可

报错2:Setup password not specified correctly

解决2:

报错3:Your password must contain at least 2 digit(s).

解决3:

报错4:浏览器执行http://110.110.110.110:110/postfixadmin/login.php输入管理员账号密码无用

tail -f /var/log/httpd/error_log

[Thu Dec 31 15:40:43.373654 2015] [:error] [pid 2916] [client 175.175.175.175:52509] PHP Warning:  session_start(): open(/var/lib/php/session/sess_1pg175mspao175iebqcfmhu0b6, O_RDWR) failed: Permission denied (13) in /var/www/html/postfixadmin/common.php on line 30, referer: http://110.110.110.110:110/postfixadmin/login.php

解决4:cd /var/lib/php之后执行chown -R vmail.vmail session即可

错误4:和网上说的vi /etc/php.ini中去掉session.save_path ='/tmp'前的;无关