注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

曾国藩的博客

 
 
 

日志

 
 

postfix-dovecot-extman-extmail邮件系统2010年实战-软件均为最新版本  

2012-04-13 16:30:00|  分类: 邮件服务器 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
http://hi.baidu.com/lijunyi0198/blog/item/0158ebf4ce8db5d6f2d385d9.html
转载自 xiutuo
最终编辑 lijunyi0198

+++++++++++++++++++++++++++++++++++++++++++++++++++++++
秀脱linux实战笔记postfix-dovcot-extman-extmail实战片篇:

   QQ:     6541657
EMAIL:xiutuo@gmail.com
+++++++++++++++++++++++++++++++++++++++++++++++++++++++

一:环境
centos5.5
postfix-2.7.1
dovecot-2.0.6
extman-1.1
extmail-1.2
mysql-5.0.77
apache-2.2.3


二:软件功能介绍
采用虚拟用户,密码采用MD5-CRYPT;
postfix 作为MTA
dovecot 作为pop3,imap,lda,并负责smtp认证,使用dovecot的磁盘限额功能(不管有没有extmail时,都可以用来限制用户可使用的磁盘容量)
extman 作为webmail管理后台,并使用该webmail的磁盘限额功能
extmail 作为webmail终端用户使用平台
mysql   作为邮件系统虚拟用户数据的存放
apache 作为运行extman和extmail,cgi的web服务器

postfix-dovecot-extman-extmail邮件系统2010年实战-软件均为最新版本 - 曾国藩 - 曾国藩的博客


三:软件下载:
http://dovecot.org/releases/2.0/dovecot-2.0.6.tar.gz
http://www.postfix.cn/source/official/postfix-2.7.1.tar.gz

四:安装前卸载自带的sendmail,postfix,dovecot
4.1 rpm安装的
rpm -qa sendmail postfix dovecot | xargs rpm -e --nodeps
如果是源码安装的,删除以下文件
4.2源码编译安装的
postfix 卸载(默认编译安装的)
rm -f /usr/lib/python2.4/site-packages/sos/plugins/postfix.py
rm -f /usr/lib/python2.4/site-packages/sos/plugins/postfix.pyc
rm -f /usr/lib/python2.4/site-packages/sos/plugins/postfix.pyo
rm -rf /usr/libexec/postfix
rm -rf /var/lib/postfix
rm -f /usr/sbin/sendmail
rm -f /usr/sbin/post*
rm -f /usr/bin/newaliases
rm -f /usr/bin/mailq
rm -rf /var/spool/postfix/*
rm -rf /etc/postfix

dovecot卸载(默认编译安装,只是指定了--sysconfdir=/etc)
rm -f /usr/lib/python2.4/site-packages/sos/plugins/dovecot*
rm -rf /usr/local/include/dovecot
rm -rf /usr/local/lib/dovecot
rm -rf /usr/local/libexec/dovecot
rm -f /usr/local/sbin/dovecot
rm -f /usr/local/share/aclocal/dovecot.m4
rm -rf /usr/local/share/doc/dovecot
rm -rf /usr/local/var/lib/dovecot
rm -rf /var/run/dovecot
rm -f /var/spool/postfix/pid/unix.dovecot
rm -f /var/spool/postfix/private/dovecot

五:配置邮件系统需要的用户和目录
5.1 用户说明以及创建相关用户
vmail作为映射虚拟用户映射的真实系统用户
postfix作为postfix软件的运行用户
dovecot作为dovect软件的运行用户
postdrop作为postfix软件用户

groupadd -g 1010 vmail
groupadd -g 1003 postfix
useradd -u 1003 -g 1003 -M -s /sbin/login postfix
useradd -u 1010 -g 1010 -M -s /sbin/login vmail
useradd -M -s /sbin/login dovecot
useradd -M -s /sbin/login postdrop
5.2 创建邮件系统用户根目录
mkdir -p /var/vmail
chown -R vmail:vmail /var/vmail

六:安装软件

6。1 安装apache
# yum -y install httpd

6.2 安装mysql
# yum -y install mysql mysql-devel

6.3 安装dovecot
安装dovecot需要的软件
# rpm -qa | grep openssl
openssl-devel-0.9.8e-12.el5_4.6
openssl-0.9.8e-12.el5_4.6

编译安装dovecot
# tar xvf dovecot-2.0.6.tar.gz
# cd dovecot-2.0.6
# ./configure --sysconfdir=/etc --with-mysql
# make
# make install

6.4 编译安装postfix
# tar xvf postfix-2.7.1.tar.gz
# cd postfix-2.7.1
# make -f Makefile.init makefiles \
'CCARGS=-DHAS_MYSQL -I/usr/include/mysql/ \
-DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\"dovecot\" ' \
'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm'
# make install

6.5 安装extmail extman需要的模块
rrdtool,perl-GD,perl-DBI,perl-File-Tai,Unix::Syslog,Encode::IMAPUTF7
----------------------------------------
rrdtool安装,通过yum源自动安装rrdtool
# vi /etc/yum.repos.d/dag.repo
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
enabled=1
#rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
搞定后,直接yum安装如下:
#yum install rrdtool
--------------------------------------
请自行安装
rpm -qa | grep perl
perl-String-CRC32-1.4-2.fc6
perl-URI-1.35-3
newt-perl-1.08-9.2.2
perl-GD-2.44-1.el5.rf
mod_perl-2.0.4-6.el5
perl-rrdtool-1.4.4-1.el5.rf
perl-DBI-1.615-1.el5.rf
perl-File-Tail-0.99.3-1.2.el5.rf
perl-5.8.8-27.el5
perl-BSD-Resource-1.28-1.fc6.1
perl-DBD-mysql-4.014-1.el5.rf
-------------------------------------
另外需要,Unix::Syslog,Encode::IMAPUTF7这个perl模块,可以通过
perl -MCPAN -e shell
命令安装
> install Unix::Syslog
> install Encode::IMAPUTF7
-------------------------------------

6.6 安装extman
# tar xvf extman-1.1.tar.gz
# mv extman-1.1 /var/www/html/extman

6.7 安装extmail
# tar xvf extmail-1.2.tar.gz
# mv extmail-1.2 /var/www/html/extmail

七: 配置整个邮件系统
7.1 配置dovecot,涉及到俩个文件/etc/dovecot/dovecot.conf,/etc/dovecot/dovecot-sql.conf.ext
# dovecot -n
# 即/etc/dovecot/dovecot.conf的内容如下
# 2.0.6: /etc/dovecot/dovecot.conf
# OS: Linux 2.6.18-164.el5 x86_64 Red Hat Enterprise Linux Server release 5.4 (Tikanga) ext3
auth_debug = yes
auth_debug_passwords = yes
auth_default_realm = pointpr.com.cn
auth_mechanisms = plain login cram-md5
auth_realms = xiutuo.cnwww.xiutuo.cnmail.xiutuo.cnpop3.xiutuo.cnsmtp.pointpr.com.cn
auth_username_format = %Lu
auth_verbose = yes
base_dir = /var/run/dovecot/
default_login_user = vmail
disable_plaintext_auth = no
mail_debug = yes
mail_gid = 1010
mail_location = maildir:/var/vmail/%d/%n/Maildir
mail_plugins = " quota"
mail_uid = 1010
passdb {
args = /etc/dovecot/dovecot-sql.conf.ext
driver = sql
}
plugin {
quota_rule = *:storage=1G:messages=10000
setting_name = quota
}
postmaster_address = postmaster@xiutuo.cn
protocols = pop3 imap
sendmail_path = /usr/bin/sendmail
service auth-worker {
group = vmail
user = vmail
}
service auth {
unix_listener /var/spool/postfix/private/auth {
group = postfix
mode = 0660
user = postfix
}
unix_listener auth-userdb {
group = postfix
mode = 0666
user = vmail
}
}
service imap-login {
inet_listener imaps {
ssl = no
}
}
service pop3-login {
inet_listener pop3s {
ssl = no
}
}
ssl = no
userdb {
args = /etc/dovecot/dovecot-sql.conf.ext
driver = sql
}
protocol lda {
auth_socket_path = /var/run/dovecot/auth-master
info_log_path = /var/log/dovecot-lda.log
log_path = /var/log/dovecot-lda-errors.log
mail_plugins = " quota"
}
protocol pop3 {
pop3_uidl_format = %08Xu%08Xv
}

/etc/dovecot/dovecot-sql.conf.ext内容如下
# cat /etc/dovecot/dovecot-sql.conf.ext
driver = mysql
default_pass_scheme = MD5-CRYPT
connect = host=localhost dbname=extmail user=extmail password=extmail
user_query = SELECT maildir,1010 AS uid, 1010 AS gid,concat('maildir:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1'
password_query = SELECT password FROM mailbox WHERE username = '%u' AND active = '1'

7.2 配置postfix
postfix涉及到的配置文件如下
# ls -1 /etc/postfix/
access
aliases
aliases.db
bounce.cf.default
canonical
filter_recipient_domains
filter_recipient_domains.db
generic
header_checks
LICENSE
main.cf
main.cf.default
makedefs.out
master.cf
mynetworks
mynetworks.deny
mysql_virtual_alias_maps.cf
mysql_virtual_domains_maps.cf
mysql_virtual_mailbox_maps.cf
relocated
reserved_ip.deny
TLS_LICENSE
transport
virtual

需要手动生成的文件
aliases.db---------------------->直接运行newaliases命令生成
filter_recipient_domains-------->通过touch /etc/postfix/filter_recipient_domains
filter_recipient_domains.db----->其中filter_recipient_domains的内容留为空,然后运行postmap /etc/postfix/filter_recipient_domains生成
mynetworks---------------------->通过touch /etc/postfix/mynetworks,内容为空即可
reserved_ip.deny---------------->通过touch /etc/postfix/reserved_ip.deny,内容为空即可
mynetworks.deny----------------->通过touch /etc/postfix/mynetworks.deny,内容为空即可

其中需要修改的文件
main.cf
master.cf
mysql_virtual_alias_maps.cf   ------>可从extman/docs/下复制过去
mysql_virtual_domains_maps.cf ------>可从extman/docs/下复制过去
mysql_virtual_mailbox_maps.cf ------>可从extman/docs/下复制过去
内容分别是
# cat main.cf | grep -v "#" | sed '/^$/d'
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
unknown_local_recipient_reject_code = 550
alias_maps = hash:/etc/postfix/aliases
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/local/man
sample_directory = /etc/postfix
readme_directory = no
myhostname = mail.xiutuo.cn
mydomain = pointpr.com.cn
inet_interfaces = all
mynetworks = $config_directory/mynetworks
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = /var/spool/postfix/private/auth
smtpd_sasl_authenticated_header = yes
smtpd_sasl_security_options = noanonymous
smtp_sasl_password_maps = mysql:$config_directory/mysql_virtual_mailbox_maps.cf
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
broken_sasl_auth_clients = yes
smtpd_helo_required = yes
disable_vrfy_command = yes
non_fqdn_reject_code = 450
invalid_hostname_reject_code = 450
maps_rbl_reject_code = 450
mailbox_command = /usr/local/libexec/dovecot/dovecot-lda
dovecot_destination_recipient_limit = 1
virtual_transport = dovecot
virtual_mailbox_domains = mysql:$config_directory/mysql_virtual_domains_maps.cf
virtual_mailbox_base = /var/vmail
virtual_mailbox_maps = mysql:$config_directory/mysql_virtual_mailbox_maps.cf
virtual_alias_maps = mysql:$config_directory/mysql_virtual_alias_maps.cf
virtual_minimum_uid = 1000
virtual_uid_maps = static:1010
virtual_gid_maps = static:1010

# cat master.cf | grep -v "#" | sed '/^$/d'
smtp      inet n       -       n       -       -       smtpd
pickup    fifo n       -       n       60      1       pickup
cleanup   unix n       -       n       -       0       cleanup
qmgr      fifo n       -       n       300     1       qmgr
tlsmgr    unix -       -       n       1000?   1       tlsmgr
rewrite   unix -       -       n       -       -       trivial-rewrite
bounce    unix -       -       n       -       0       bounce
defer     unix -       -       n       -       0       bounce
trace     unix -       -       n       -       0       bounce
verify    unix -       -       n       -       1       verify
flush     unix n       -       n       1000?   0       flush
proxymap unix -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix -       -       n       -       -       smtp
relay     unix -       -       n       -       -       smtp
-o smtp_fallback_relay=
showq     unix n       -       n       -       -       showq
error     unix -       -       n       -       -       error
retry     unix -       -       n       -       -       error
discard   unix -       -       n       -       -       discard
local     unix -       n       n       -       -       local
virtual   unix -       n       n       -       -       virtual
lmtp      unix -       -       n       -       -       lmtp
anvil     unix -       -       n       -       1       anvil
scache    unix -       -       n       -       1       scache
dovecot   unix -       n       n       -       -       pipe
flags=DRhu user=vmail argv=/usr/local/libexec/dovecot/dovecot-lda -f ${sender} -d ${recipient}
submission inet n - - - - smtpd
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_sasl_type=dovecot
-o smtpd_sasl_path=private/auth
-o smtpd_sasl_security_options=noanonymous
-o smtpd_sasl_local_domain=$myhostname
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
-o smtpd_sender_login_maps= mysql:$config_directory/mysql_virtual_mailbox_maps.cf
-o smtpd_sender_restrictions=reject_sender_login_mismatch

# cat mysql_virtual_alias_maps.cf
user = extmail
password = extmail
hosts = localhost
dbname = extmail
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'

# cat mysql_virtual_domains_maps.cf
user = extmail
password = extmail
hosts = localhost
dbname = extmail
query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'


# cat mysql_virtual_mailbox_maps.cf
user = extmail
password = extmail
hosts = localhost
dbname = extmail
query = SELECT username FROM mailbox WHERE username='%s' AND active = '1'

----------------------------------------------------------------------------
注意,配置extmail,extman,apache的时候,需要注意
apache必须使用vmail这个用户来启动(虚拟用户映射的系统真实用户),而且
extman和extmail中的cgi文件夹的权限必须属于vmail用户和vmail用户组,否则权限问题出错
——-------------------------------------------------------------------------
7.3 配置apache

vi /etc/httpd/conf/httpd.conf
#修改apache用户和组
User vmail
Group vmail
#运行cgi模块的配置
#在<Directory "/var/www/html">……</Directory>后面增加如下
ScriptAlias /extmail/cgi/ /var/www/html/extmail/cgi/
Alias /extmail /var/www/html/extmail/html/
ScriptAlias /extman/cgi/ /var/www/html/extman/cgi/
Alias /extman /var/www/html/extman/html/

7.4 配置extman
# chown -R vmail:vamil /var/www/html/extman/cgi
# mkdir -p /var/www/html/extman/sessions/
# chown vmail:vmail /var/www/html/extman/sessions/
导入extman数据库脚本和初始化数据
# mysql -uroot -p < /var/www/html/extman/extmail.sql
# mysql -uroot -p < /var/www/html/extman/init.sql
# vi /var/www/html/extman/webman.cf
SYS_CONFIG = /var/www/html/extman/
SYS_LANGDIR = /var/www/html/extman/lang
SYS_TEMPLDIR = /var/www/html/extman/html
SYS_MAILDIR_BASE = /var/vmail
#-------------------------------------------
# session保存路径/var/www/html/extman/sessions/,需要手工建立 session目录,并赋予vmail用户,即apache运行用户
# 注意,extmail
# mkdir -p /var/www/html/extman/sessions/
# chown vmail:vmail /var/www/html/extman/sessions/
#-----------------------------------------
SYS_SESS_DIR = /var/www/html/extman/sessions/
# 登入页面验证码关闭,1表示开启
SYS_CAPTCHA_ON = 0
# 语言,中文啦
# SYS_LANG = zh_CN
SYS_MIN_UID = 1010
SYS_MIN_GID = 1010
# 虚拟用户需要系统真实映射用户的UID和GID
SYS_DEFAULT_UID = 1010
SYS_DEFAULT_GID = 1010
# MYSQL数据库相关的配置
SYS_MYSQL_USER = webman
SYS_MYSQL_PASS = webman
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = localhost
SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock
# table name
SYS_MYSQL_TABLE = manager
SYS_MYSQL_ATTR_USERNAME = username
SYS_MYSQL_ATTR_PASSWD = password
其他的默认啊就可以。。。

7.5 配置extmail
# chown -R vmail:vamil /var/www/html/extmail/cgi
# vi /var/www/html/extmail/webmail.cf
SYS_CONFIG = /var/www/html/extmail/
SYS_LANGDIR = /var/www/html/extmail/lang
SYS_TEMPLDIR = /var/www/html/extmail/html
SYS_USER_LANG = zh_CN
SYS_USER_CHARSET = utf-8
# 用户邮件存放目录
SYS_MAILDIR_BASE = /var/vmail
# mysql数据库相关设置
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = localhost
SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock
# table name
SYS_MYSQL_TABLE = mailbox
SYS_MYSQL_ATTR_USERNAME = username
SYS_MYSQL_ATTR_DOMAIN = domain
SYS_MYSQL_ATTR_PASSWD = password
#全局通信录的启用
SYS_G_ABOOK_FILE_PATH = /var/www/html/extmail/globabook.cf
其他的默认,即可工作

八。启动整个邮件系统
8.1 启动mysql
# service mysqld start
8.2 启动dovecot
# dovecot -c /etc/dovecot/dovecot.conf
8.3 启动postfix
# postfix start
# chmod 766 /var/run/dovecot/auth-master

-----------------------------------------------------------
该/var/run/dovecot/auth-master文件需要读权限,否则发送邮件的报错,应该dovecot的bug,
本来可以在dovecot中一下段设置mode属性的,但是dovecot2.0.6不支持,2版本以下是支持的!!!
service auth-worker {
group = vmail
user = vmail
}
---------------------------------------------------------
8.4 启动apache
# service httpd start

8.5启动extman的cmdserver,可以控制postfix,mysql...
/var/www/html/extman/daemon/cmdserver -d

九。 收发测试
9.1 通过邮件客户端测试
9.2 通过extmail的web页面测试
请自行测试

十。通信录功能实现脚本
abook.sh ------> 生成用户通信录,配置文件group.txt
group.sh-------> 生成用户通信录组,配置文件group.txt
globabook.sh---> 生成全局通信录,配置文件group.txt
mkdir_user.sh--> 生成用户邮件目录,extmail的bug,如果只通过web页面收发邮件的话,不自动生成相应用户邮件目录。通过邮件客户端没有这个问题
mailbox.sh-----> 批量生成用户邮箱,配置文件group.txt
alias.sh-------> 按照用户在通信录组自动生成一个可以群发到改组的别名帐号,配置文件group.txt和alias.txt

group.txt------>以上脚本需要用到的配置文件
alias.txt------>以上脚本需要用到的配置文件

脚本和配置文件内容如下
# cat abook.sh
# /bin/sh
#set -x
echo '"Name","Email","NickName","IMaol","IMicq","IMgoogle","IMmsn","IMqq","IMskype","HomeTel","Mobile","HomeAddress","HomeCity","HomeState","HomeZip","HomeCountry","Company","Job","WorkMail","WorkTel","WorkFax","WorkAddress","WorkCity","WorkState","WorkZip","WorkCountry","OtherMail","OtherPhone","WebSite","BirthDay","Notes","Picture"' >abook.cf
cat group.txt | awk '{print "\""$1"\",\""$2"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\""$3"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"" }' >>abook.cf


# cat group.sh
#!/bin/bash
#set -x
## 创建邮件目录
cat group.txt | while read line
do
domain=`echo $line | awk '{print $2}' | awk -F'@' '{print $2}'`
uid=`echo $line | awk '{print $2}' | awk -F'@' '{print $1}'`
maildir="/var/vmail/$domain/$uid/Maildir/"
mkdir -p $maildir
done
chown -R vmail:vmail /var/vmail

###创建通信
dos2unix group.txt
cat group.txt | awk '{print $3}' | sort -u > group_tmp
echo -e "\"GrpName\",\"GrpMember\"\n" >group.cf
for i in `cat group_tmp`
do
groupcontext=`grep "$i" group.txt | awk '{print "\"\"\""$1"\"\" <"$2">\","}' | tr -d "\n" | sed 's/,$//g'`
echo -e "\"$i\",$groupcontext" >>group.cf
done
sed -i '/^$/d' group.cf
echo '"Name","Email","NickName","IMaol","IMicq","IMgoogle","IMmsn","IMqq","IMskype","HomeTel","Mobile","HomeAddress","HomeCity","HomeState","HomeZip","HomeCountry","Company","Job","WorkMail","WorkTel","WorkFax","WorkAddress","WorkCity","WorkState","WorkZip","WorkCountry","OtherMail","OtherPhone","WebSite","BirthDay","Notes","Picture"' >abook.cf
cat group.txt | awk '{print "\""$1"\",\""$2"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\""$3"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"" }' >>abook.cf
ls -l /var/vmail/*/*/* | grep Maildir | awk -F: '{print $1}' > dirs
for b in `cat dirs`
do
cp -f abook.cf $b
cp -f group.cf $b
done

# cat globabook.sh
#!/bin/bash
#set -x
echo "Name,Mail,Company,Phone">globabook.cf
awk '{print "\""$1"\",\""$2"\",\""$3"\",\"\""}' group.txt >>globabook.cf
cp -f globabook.cf /var/www/html/extmail/

# cat mailbox.sh
#!/bin/bash
#set -x
echo "use extmail" >mailbox.sql
cat group.txt | while read line
do
username=`echo $line | awk '{print $2}'`
uid=`echo $line | awk '{print $2}' | awk -F'@' '{print $1}'`
password="\$1\$Mvq6PqaP\$oz729960nw7a1jTUClL0L0"
clearpwd=""
name=`echo $line | awk '{print $1}'`
mailhost=""
maildir="xiutuo.cn/$uid/Maildir/"
homedir="xiutuo.cn/$uid"
quota="52428800"
netdiskquota="52428800"
domain="xiutuo.cn"
uidnumber="1010"
gidnumber="1010"
createdate="2010-10-26 16:10:15"
expiredate="0000-00-00"
active="1"
disablepwdchange="0"
disablesmtpd="0"
disablewebmail="0"
disablenetdisk="0"
disableimap="0"
disablepop3="0"
question=""
answer=""
echo "INSERT INTO mailbox VALUES (\"$username\",\"$uid\",\"$password\",\"$clearpwd\",\"$name\",\"$mailhost\",\"$maildir\",\"$homedir\",\"$quota\",\"$netdiskquota\",\"$domain\",\"$uidnumber\",\"$gidnumber\",\"$createdate\",\"$expiredate\",\"$active\",\"$disablepwdchange\",\"$disablesmtpd\",\"$disablesmtp\",\"$disablewebmail\",\"$disablenetdisk\",\"$disableimap\",\"$disablepop3\",\"$question\",\"$answer\");" >>mailbox.sql
done
mysql -u extmail -p'extmail' < mailbox.sql


# cat mkdir_user.sh
#!/bin/bash
# set -x
cat group.txt | while read line
do
domain=`echo $line | awk '{print $2}' | awk -F'@' '{print $2}'`
uid=`echo $line | awk '{print $2}' | awk -F'@' '{print $1}'`
maildir="/var/vmail/$domain/$uid/Maildir/"
mkdir -p $maildir
done
chown -R vmail:vmail /var/vmail

# cat alias.sh
#!/bin/bash
echo "use extmail" >alias.sql
domain_name="xiutuo.cn"
cat alias.txt | while read line
do
alias_group="`echo $line | awk '{print $1}'`@$domain_name"
flag=`echo $line | awk '{print $2}'`
alias_member=`cat group.txt | grep "$flag" | awk '{print $2}' | sed 's/$/,/g' | tr -d "\n" | sed 's/,$//g'`
echo "INSERT INTO alias VALUES (\"$alias_group\",\"$alias_member\",\"$domain_name\",\"2010-10-26 16:05:34\",\"1\");" >> alias.sql
done
all_member=`cat group.txt | awk '{print $2}' | sed 's/$/,/g' | tr -d "\n" | sed 's/,$//g'`
echo "INSERT INTO alias VALUES (\"all@$domain_name\",\"$all_member\",\"$domain_name\",\"2010-10-26 16:05:34\",\"1\");" >> alias.sql
mysql -u extmail -p'extmail' < alias.sql

# cat group.txt
张三 zhangsan@xiutuo.cn 招商部
李四 lisi@xiutuo.cn 运营中心
王五 wangwu@xiutuo.cn 客户部

# cat alias.txt
zs 招商部
yyzx 运营中心
kf 客户部

附录
extman 数据库脚本:all_extmail.sql
dovecot配置文件
postfix配置文件

  评论这张
 
阅读(1365)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018