把生成的hash值复制到
$CONF['setup_password'] = 'changeme'
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
建立删除虚拟邮箱脚本,脚本名称 /usr/local/bin/maildir-deletion.sh ,脚本内容如下:
#
# 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
建立删除目录
[root@mail html]# mkdir /var/vmail/deleted-maildirs
[root@mail html]# chown -R vmail.vmail /var/vmail/deleted-maildirs/
[root@mail html]# chmod 750 /usr/local/bin/maildir-*
[root@mail html]# chown vmail.vmail /usr/local/bin/maildir-*
在 /etc/sudoers 增加一行
vmail ALL = NOPASSWD: /usr/local/bin/maildir-creation.sh
vmail ALL = NOPASSWD: /usr/local/bin/maildir-deletion.sh
#Defaults requiretty
修改create-mailbox.php 文件,229行内容应该是:
db_log ($SESSID_USERNAME, $fDomain, 'create_mailbox', "$fUsername");
system("sudo /usr/local/bin/maildir-creation.sh $fDomain ".$_POST['fUsername']);
db_log ($SESSID_USERNAME, $fDomain, 'delete_mailbox', $fDelete);
$userarray=explode("@",$fDelete);
$user=$userarray[0];
$domain=$userarray[1];
system("sudo /usr/local/bin/maildir-deletion.sh $domain $user");
4、配置Postfix
修改/etc/postfix/main.cf文件:
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
mydestination = localhost
mynetworks_style = host
#
# The VIRTUAL_README document gives information about the many forms
# of domain hosting that Postfix supports.
# See: http://www.howtoforge.com/virtual-users-domains-postfix-courier-mysql-squirrelmail-ubuntu8.04-p2
# The follwing lines connect Postfix with the MySQL database that contains information about
# the virtual users/accounts hosted. See proxymap(8) virtual(5) and mysql_table(5)
#
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf
#
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf
#
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
#
# Additional for quota support
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, this user has exceeded their disk space quota, please try again later.
virtual_overquota_bounce = yes
#
#Specify the user/group that owns the mail folders. I'm not sure if this is strictly necessary when using Dovecot's LDA.
virtual_uid_maps = static:2000
virtual_gid_maps = static:2000
#
#Specifies which tables proxymap can read: http://www.postfix.org/postconf.5.html#proxy_read_maps
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
创建Mysql脚本
[root@mail ~]# vim /etc/postfix/mysql_virtual_domains_maps.cf
password = 123123
hosts = localhost
dbname = mail
query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'
#optional query to use when relaying for backup MX
#query = SELECT domain FROM domain WHERE domain='%s' AND backupmx = '0' AND active = '1'
[root@mail ~]# vim /etc/postfix/mysql_virtual_alias_maps.cf
password = 123123
hosts = localhost
dbname = mail
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'
user = admin
password = 123123
hosts = localhost
dbname = mail
query = SELECT CONCAT(domain,'/',maildir) FROM mailbox WHERE username='%s' AND active = '1'
[root@mail ~]# vim /etc/postfix/mysql_virtual_mailbox_limit_maps.cf
password = 123123
dbname = mail
query = SELECT quota FROM mailbox WHERE username='%s' AND active = '1'
SMTP加密设定
#
# The following options set parameters needed by Postfix to enable
# SMTP AUTH support using Dovecot's SASL component for authentication of mail clients.
# See: /usr/share/doc/postfix-2.3.3/README_FILES/SASL_README - http://www.postfix.org/SASL_README.html
# And /usr/share/doc/dovecot-1.0.7/wiki/HowTo.PostfixAndDovecotSASL.txt - http://wiki.dovecot.org/HowTo/PostfixAndDovecotSASL
#
# Turns on sasl authorization
smtpd_sasl_auth_enable = yes
#
#Use dovecot for authentication
smtpd_sasl_type = dovecot
#
# Path to UNIX socket for SASL
smtpd_sasl_path = /var/run/dovecot/auth-client
#
#Disable anonymous login. We don't want to run an open relay for spammers.
smtpd_sasl_security_options = noanonymous
#
#Adds support for email software that doesn't follow RFC 4954.
#This includes most versions of Microsoft Outlook before 2007.
broken_sasl_auth_clients = yes
#
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
使用Dovecot做为投递
#
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1
dovecot unix - n n - - pipe
flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/dovecot-lda -f ${sender} -d ${recipient}
因为配置文件比较分散,我把需要修改的配置文件的内容列出来
listen = *
dict {
quota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext
}
!include conf.d/*.conf
[root@mail ~]# vim /etc/dovecot/conf.d/10-auth.conf
auth_mechanisms = plain login cram-md5
!include auth-sql.conf.ext
[root@mail ~]# vim /etc/dovecot/conf.d/10-mail.conf
mbox_write_locks = fcntl
[root@mail ~]# vim /etc/dovecot/conf.d/10-master.conf
inet_listener imap {
}
inet_listener imaps {
}
}
service pop3-login {
inet_listener pop3 {
}
inet_listener pop3s {
}
}
service lmtp {
unix_listener lmtp {
}
}
service imap {
}
service pop3 {
}
service auth {
unix_listener auth-userdb {
mode = 0600
user = vmail
group = vmail
}
unix_listener auth-client {
mode = 0600
user = postfix
group = postfix
}
}
service auth-worker {
}
service dict {
unix_listener dict {
mode = 0600
user = vmail
group = vmail
}
}
[root@mail ~]# vim /etc/dovecot/conf.d/15-lda.conf
[root@mail ~]# vim /etc/dovecot/conf.d/20-imap.conf
mail_plugins = quota imap_quota
}
[root@mail ~]# vim /etc/dovecot/conf.d/20-pop3.conf
pop3_uidl_format = %08Xu%08Xv
mail_plugins = quota
}
[root@mail ~]# vim /etc/dovecot/conf.d/90-quota.conf
quota_rule = *:storage=1G
}
plugin {
}
plugin {
quota = dict:User quota::proxy::quota
}
plugin {
}
[root@mail ~]# vim /etc/dovecot/dovecot-sql.conf.ext
connect = host=localhost dbname=mail user=admin password=123123
default_pass_scheme = CRAM-MD5
[root@mail ~]# vim /etc/dovecot/dovecot-dict-sql.conf.ext
map {
pattern = priv/quota/storage
table = quota2
username_field = username
value_field = bytes
}
map {
pattern = priv/quota/messages
table = quota2
username_field = username
value_field = messages
}
6、测试SMTP与POP3服务
创建虚拟域
创建邮箱
连接25端口
[root@mail ~]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.example.com ESMTP Postfix
ehlo example.com
250-mail.example.com
250-PIPELINING
250-SIZE 20480000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN CRAM-MD5
250-AUTH=PLAIN LOGIN CRAM-MD5
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
连接110端口
[root@mail ~]# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user test@example.com
+OK
pass test
+OK Logged in.
已经自动创建邮箱
[root@mail ~]# ll /var/vmail/example.com/test/Maildir/
total 40
drwx------. 2 vmail vmail 4096 Apr 26 05:44 cur
-rw-------. 1 vmail vmail 16384 Apr 26 05:43 dovecot.index.cache
-rw-------. 1 vmail vmail 608 Apr 26 05:44 dovecot.index.log
-rw-------. 1 vmail vmail 95 Apr 26 05:43 dovecot-uidlist
-rw-------. 1 vmail vmail 8 Apr 26 05:43 dovecot-uidvalidity
-r--r--r--. 1 vmail vmail 0 Apr 26 05:43 dovecot-uidvalidity.4f986fe9
drwx------. 2 vmail vmail 4096 Apr 26 05:44 new
drwx------. 2 vmail vmail 4096 Apr 26 05:43 tmp
收发邮件正常