1、mail部署說明php
2、安裝準備html
3、LMAP環境配置mysql
四、配置postfixadminlinux
五、配置postfixweb
6、配置dovecotsql
7、測試SMTP和POP3服務數據庫
8、配置Roundcubemailapache
建立一個vmail用戶,用做管理虛擬郵箱的文件夾vim
useradd
-u 2000 -d
/var/vmail
-m -s
/sbin/nologin
vmail
1 [root@mail ~]# tar xf postfixadmin-2.93.tar.gz -C /var/www/html/ 2 [root@mail ~]# cd /var/www/html/ 3 [root@mail html]# ls 4 index.php postfixadmin-2.93 5 [root@mail html]# mv postfixadmin-2.93 postfixadmin 6 [root@mail html]# ls 7 index.php postfixadmin 8 [root@mail html]#
1 [root@mail html]# cd postfixadmin/ 2 #修改前先備份一下配置文件 3 [root@mail postfixadmin]# cp config.inc.php config.inc.php.bak 4 [root@mail postfixadmin]# cp setup.php setup.php.bak 5 [root@mail postfixadmin]# vim config.inc.php 6 #找到下面幾行並修改 7 $CONF['configured'] = true; 8 $CONF['database_type'] = 'mysql'; 9 $CONF['database_host'] = 'localhost'; 10 $CONF['database_user'] = 'postfix'; 11 $CONF['database_password'] = 'postfix'; 12 $CONF['database_name'] = 'postfix'; 13 $CONF['admin_email'] = 'postmaster@free.com'; 14 $CONF['encrypt'] = 'dovecot:CRAM-MD5'; 15 $CONF['dovecotpw'] = "/usr/bin/doveadm pw"; 16 $CONF['domain_path'] = 'YES'; 17 $CONF['domain_in_mailbox'] = 'NO'; 18 $CONF['aliases'] = '1000'; 19 $CONF['mailboxes'] = '1000'; 20 $CONF['maxquota'] = '1000'; 21 $CONF['fetchmail'] = 'NO'; 22 $CONF['quota'] = 'YES'; 23 $CONF['used_quotas'] = 'YES'; 24 $CONF['new_quota_table'] = 'YES';
1 mysql> create database postfix;
2 mysql> grant all on postfix.* to postfix@'localhost' identified by 'postfix'; 3 mysql> flush privileges;
1 [root@mail html]# mysql -u postfix -p
2 Enter password: 3 Welcome to the MySQL monitor. Commands end with ; or \g. 4 Your MySQL connection id is 53806 5 Server version: 5.6.31 MySQL Community Server (GPL) 6 7 Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 8 9 Oracle is a registered trademark of Oracle Corporation and/or its 10 affiliates. Other names may be trademarks of their respective 11 owners. 12 13 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 14 15 mysql> show databases; 16 +--------------------+ 17 | Database | 18 +--------------------+ 19 | information_schema | 20 | postfix | 21 | test | 22 +--------------------+ 23 3 rows in set (0.00 sec) 24 mysql> use postfix 25 Database changed 26 mysql>
1 [root@mail postfixadmin]# yum install -y dovecot dovecot-devel dovecot-mysql 2 [root@mail postfixadmin]# chkconfig dovecot on #加入開機自啓動 3 [root@mail postfixadmin]# chkconfig dovecot --list 4 dovecot 0:關閉 1:關閉 2:啓用 3:啓用 4:啓用 5:啓用 6:關閉 5 [root@mail postfixadmin]#
1 [root@mail ~]#vim /usr/local/bin/maildir-creation.sh 2 #!/bin/bash 3 # 4 HOME_DIR="/var/vmail" 5 USER_NAME="vmail" 6 GROUP_NAME="vmail" 7 if [ ! -d ${HOME_DIR}/$1 ] ; then 8 mkdir ${HOME_DIR}/$1 9 chown -R ${USER_NAME}.${GROUP_NAME} ${HOME_DIR}/$1 10 fi 11 mkdir ${HOME_DIR}/$1/$2 12 chown -R ${USER_NAME}.${GROUP_NAME} ${HOME_DIR}/$1/$2
1 [root@mail ~]#vim /usr/local/bin/maildir-deletion.sh 2 #!/bin/bash 3 # 4 # vmta ALL = NOPASSWD: /usr/local/bin/maildir-deletion.sh 5 # 6 if [ $# -ne 2 ] ; then 7 exit 127 8 fi 9 DOMAIN="$1" 10 USER="$2" 11 HOME_DIR="/var/vmail" 12 USER_DIR="${HOME_DIR}/${DOMAIN}/${USER}" 13 TRASH_DIR="${HOME_DIR}/deleted-maildirs" 14 DATE=`date "+%Y%m%d_%H%M%S"` 15 if [ ! -d "${TRASH_DIR}/${DOMAIN}" ] ; then 16 mkdir -p "${TRASH_DIR}/${DOMAIN}" 17 fi 18 if [ -d "${USER_DIR}" ] ; then 19 mv ${USER_DIR} ${TRASH_DIR}/${DOMAIN}/${USER}-${DATE} 20 fi
1 [root@mail ~]# mkdir /var/vmail/deleted-maildirs 2 [root@mail ~]# chown -R vmail.vmail /var/vmail/deleted-maildirs/
1 [root@mail ~]# chmod 750 /usr/local/bin/maildir-* 2 [root@mail ~]# chown vmail.vmail /usr/local/bin/maildir-*
1 [root@mail ~]#vim /etc/sudoers 2 #在 /etc/sudoers 最後增長兩行 3 vmail ALL = NOPASSWD: /usr/local/bin/maildir-creation.sh 4 vmail ALL = NOPASSWD: /usr/local/bin/maildir-deletion.sh 5 #在/etc/sudoers 註釋掉下面內容 6 #Defaults requiretty 7 :wq! #因爲這個文件是隻讀的,因此得強制保存並退出
1 [root@mail ~]# cd /var/www/html/postfixadmin/ 2 [root@mail postfixadmin]# vim create-mailbox.php 3 修改create-mailbox.php 文件,229行內容應該是: 4 db_log ($SESSID_USERNAME, $fDomain, 'create_mailbox', "$fUsername"); 5 在該行前面增長下面一行, 6 system("sudo /usr/local/bin/maildir-creation.sh $fDomain ".$_POST['fUsername']); 7 [root@mail postfixadmin]# vim delete.php 8 修改delete.php 文件,146行內容應該是, 9 db_log ($SESSID_USERNAME, $fDomain, 'delete_mailbox', $fDelete); 10 在該行下面增長下面4行, 11 $userarray=explode("@",$fDelete); 12 $user=$userarray[0]; 13 $domain=$userarray[1]; 14 system("sudo /usr/local/bin/maildir-deletion.sh $domain $user");
------------------------------至此postfixadmin配置所有完成---------------------------瀏覽器
注:Postfix用CentOS6.5系統自帶的,由於CentOS6.5裏面的postfix包已經支持mysql
1 [root@mail deleted-maildirs]# rpm -qa | grep postfix 2 postfix-2.6.6-6.el6_7.1.x86_64
1 [root@mail ~]# vim /etc/postfix/main.cf 2 #基本配置 3 myhostname = mail.yourdomain.com 4 mydomain = yourdomain.com 5 myorigin = $mydomain 6 inet_interfaces = all 7 mynetworks_style = host 8 mynetworks = 192.168.18/24, 127.0.0.0/8 9 #虛擬域名配置 10 virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf 11 virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf 12 virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf 13 # Additional for quota support 14 virtual_create_maildirsize = yes 15 virtual_mailbox_extended = yes 16 virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf 17 virtual_mailbox_limit_override = yes 18 virtual_maildir_limit_message = Sorry, this user has exceeded their disk space quota, please try again later. 19 virtual_overquota_bounce = yes 20 #Specify the user/group that owns the mail folders. I'm not sure if this is strictly necessary when using Dovecot's LDA. 21 virtual_uid_maps = static:2000 22 virtual_gid_maps = static:2000 23 #Specifies which tables proxymap can read: http://www.postfix.org/postconf.5.html#proxy_read_maps 24 proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps 25 [root@mail ~]# postconf #檢查配置文件是否有錯誤
1 [root@mail ~]# vim /etc/postfix/mysql_virtual_domains_maps.cf 2 user = postfix 3 password = postfix 4 hosts = localhost 5 dbname = postfix 6 query = SELECT domain FROM domain WHERE domain='%s' AND active = '1' 7 #optional query to use when relaying for backup MX 8 #query = SELECT domain FROM domain WHERE domain='%s' AND backupmx = '0' AND active = '1'
1 [root@mail ~]# vim /etc/postfix/mysql_virtual_alias_maps.cf 2 user = postfix 3 password = postfix 4 hosts = localhost 5 dbname = postfix 6 query = SELECT goto FROM alias WHERE address='%s' AND active = '1'
1 [root@mail ~]# vim /etc/postfix/mysql_virtual_mailbox_maps.cf 2 user = postfix 3 password = postfix 4 hosts = localhost 5 dbname = postfix 6 query = SELECT CONCAT(domain,'/',maildir) FROM mailbox WHERE username='%s' AND active = '1'
1 [root@mail ~]# vim /etc/postfix/mysql_virtual_mailbox_limit_maps.cf 2 user = postfix 3 password = postfix 4 hosts = localhost 5 dbname = postfix 6 query = SELECT quota FROM mailbox WHERE username='%s' AND active = '1'
1 [root@mail ~]# postconf -a 2 cyrus 3 dovecot
1 [root@mail ~]#vim /etc/postfix/main.cf 2 #SASL SUPPORT FOR CLIENTS 3 # Turns on sasl authorization 4 smtpd_sasl_auth_enable = yes 5 #Use dovecot for authentication 6 smtpd_sasl_type = dovecot 7 # Path to UNIX socket for SASL 8 smtpd_sasl_path = /var/run/dovecot/auth-client 9 #Disable anonymous login. We don't want to run an open relay for spammers. 10 smtpd_sasl_security_options = noanonymous 11 #Adds support for email software that doesn't follow RFC 4954. 12 #This includes most versions of Microsoft Outlook before 2007. 13 broken_sasl_auth_clients = yes 14 # 15 smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
1 [root@mail ~]# vim /etc/postfix/main.cf 2 # TRANSPORT MAP 3 virtual_transport = dovecot 4 dovecot_destination_recipient_limit = 1 5 #修改master.cf文件 6 [root@mail ~]# vim /etc/postfix/master.cf 7 #在最後增長這兩行,注意flags前面有兩個空格,否則會報錯 8 dovecot unix - n n - - pipe, 9 flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/dovecot-lda -f ${sender} -d ${recipient}
------------------------------至此postfix配置所有完成---------------------------
1 [root@mail ~]# vim /etc/dovecot/dovecot.conf 2 protocols = imap pop3 3 listen = * 4 dict { 5 quota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext 6 } 7 !include conf.d/*.conf
1 [root@mail ~]# vim /etc/dovecot/conf.d/10-auth.conf 2 disable_plaintext_auth = no 3 auth_mechanisms = plain login cram-md5 4 !include auth-sql.conf.ext
1 [root@mail ~]# vim /etc/dovecot/conf.d/10-mail.conf 2 mail_location = maildir:%hMaildir 3 mbox_write_locks = fcntl
1 [root@mail ~]# vim /etc/dovecot/conf.d/10-master.conf 2 service imap-login { 3 inet_listener imap { 4 } 5 inet_listener imaps { 6 } 7 } 8 service pop3-login { 9 inet_listener pop3 { 10 } 11 inet_listener pop3s { 12 } 13 } 14 service lmtp { 15 unix_listener lmtp { 16 } 17 } 18 service imap { 19 } 20 service pop3 { 21 } 22 service auth { 23 unix_listener auth-userdb { 24 mode = 0600 25 user = vmail 26 group = vmail 27 } 28 #新加下面一段,爲smtp作認證 29 unix_listener auth-client { 30 mode = 0600 31 user = postfix 32 group = postfix 33 } 34 } 35 service auth-worker { 36 } 37 service dict { 38 unix_listener dict { 39 mode = 0600 40 user = vmail 41 group = vmail 42 } 43 }
1 [root@mail ~]# vim /etc/dovecot/conf.d/15-lda.conf 2 protocol lda { 3 mail_plugins = quota 4 postmaster_address = postmaster@free.com #管理員郵箱 5 }
1 [root@mail ~]# vim /etc/dovecot/conf.d/20-imap.conf 2 protocol imap { 3 mail_plugins = quota imap_quota 4 }
1 [root@mail ~]# vim /etc/dovecot/conf.d/20-pop3.conf 2 protocol pop3 { 3 pop3_uidl_format = %08Xu%08Xv 4 mail_plugins = quota 5 }
1 [root@mail ~]# vim /etc/dovecot/conf.d/90-quota.conf 2 plugin { 3 quota_rule = *:storage=1G 4 } 5 plugin { 6 } 7 plugin { 8 quota = dict:User quota::proxy::quota 9 } 10 plugin { 11 }
1 [root@mail ~]# vim /etc/dovecot/dovecot-sql.conf.ext 2 driver = mysql 3 connect = host=localhost dbname=postfix user=postfix password=postfix 4 default_pass_scheme = CRAM-MD5 5 user_query = SELECT CONCAT('/var/vmail/', maildir) AS home, 2000 AS uid, 2000 AS gid, CONCAT('*:bytes=', quota) as quota_rule FROM mailbox WHERE username = '%u' AND active='1' 6 password_query = SELECT username AS user, password, CONCAT('/var/vmail/', maildir) AS userdb_home, 2000 AS userdb_uid, 2000 AS userdb_gid, CONCAT('*:bytes=', quota) as userdb_quota_rule FROM mailbox WHERE username = '%u' AND active='1'
1 [root@mail ~]# vim /etc/dovecot/dovecot-dict-sql.conf.ext 2 connect = host=localhost dbname=postfix user=postfix password=postfix 3 map { 4 pattern = priv/quota/storage 5 table = quota2 6 username_field = username 7 value_field = bytes 8 } 9 map { 10 pattern = priv/quota/messages 11 table = quota2 12 username_field = username 13 value_field = messages 14 }
1 [root@mail ~]# service postfix restart 2 關閉 postfix: [肯定] 3 啓動 postfix: [肯定] 4 [root@mail ~]# service dovecot restart 5 中止 Dovecot Imap: [失敗] 6 正在啓動 Dovecot Imap: [肯定]
------------------------------至此dovecot配置所有完成---------------------------
1 [root@mail ~]# tar -xf roundcubemail-0.9.0.tar.gz -C /var/www/html/ 2 [root@mail ~]# cd /var/www/html/ 3 [root@mail html]# ls 4 admin index.php phpmyadmin roundcubemail-0.9.0 5 [root@mail html]# mv roundcubemail-0.9.0 webmail 6 [root@mail html]# ls 7 admin index.php phpmyadmin webmail 8 [root@mail html]#
1 [root@mail installer]# vim /etc/php.ini 2 date.timezone = Asia/Shanghai
1 [root@mail installer]# vim /etc/httpd/conf/httpd.conf 2 PHPIniDir "/etc/php.ini" 3 [root@mail installer]# service httpd restart 4 Stopping httpd: [ OK ] 5 Starting httpd: [ OK ] 6 [root@mail installer]#
1 [root@mail ~]# cd /var/www/html/ 2 [root@mail html]# ll 3 total 16 4 drwxrwxr-x 14 1000 1010 4096 Jul 11 05:25 admin 5 -rw-r--r-- 1 root root 18 Jul 11 04:12 index.php 6 drwxr-xr-x 9 root root 4096 Jul 11 04:17 phpmyadmin 7 drwxr-xr-x 11 501 80 4096 Jun 16 23:10 webmail 8 [root@mail html]# chown -R vmail.vmail admin 9 [root@mail html]# chown -R vmail.vmail phpmyadmin 10 [root@mail html]# chown -R vmail.vmail webmail
1 [root@mail html]# vim /etc/php.ini 2 session.save_path = "/var/lib/php/session"
1 [root@mail html]# cd /var/lib/php/ 2 [root@mail php]# ll 3 total 4 4 drwxrwx--- 2 root apache 4096 Feb 22 10:56 session 5 [root@mail php]# chown -R .vmail session/ 6 [root@mail php]# ll 7 total 4 8 drwxrwx--- 2 root vmail 4096 Feb 22 10:56 session 9 [root@mail php]#
1 [root@mail ~]# cd /var/www/html/webmail/config/
2 [root@mail config]# ll
3 total 92
4 -rw-r--r-- 1 root root 2905 Jul 10 22:15 db.inc.php 5 -rw-r--r-- 1 vmail vmail 2893 Jun 16 23:10 db.inc.php.dist 6 -rw-r--r-- 1 root root 38438 Jul 10 22:15 main.inc.php 7 -rw-r--r-- 1 vmail vmail 38414 Jun 16 23:10 main.inc.php.dist 8 -rw-r--r-- 1 vmail vmail 2731 Jun 16 23:10 mimetypes.php 9 [root@mail config]#
1 mysql> CREATE DATABASE roundcubemail; 2 Query OK, 1 row affected (0.00 sec) 3 mysql> GRANT ALL PRIVILEGES ON roundcubemail.* TO roundcubemail@localhost IDENTIFIED BY 'roundcubemail'; 4 FLUSH PRIVILEGES;Query OK, 0 rows affected (0.01 sec) 5 mysql> FLUSH PRIVILEGES; 6 Query OK, 0 rows affected (0.00 sec)