邮件服务器postfix+dovecot+extmail(需要lamp环境)
修改主机IP和主机名以及DNS服务器
配置DNS服务
shell>vim /var/named/chroot/etc/named.conf #将参数localhost修改为any
shell>vim /var/named/chroot/etc/named.rfc1912.zones #添加邮件服务器的管理域
shell>vim /var/named/chroot/var/named/gz.com.zone #在域中添加资源记录
安装需要的rpm软件包
yum install mysql mysql-devel openssl-devel dovecot perl-DBD-MySQL tcl tcl-devel libart_lgpl libart_lgpl-devel libtool-ltdl libtool-ltdl-devel expect
建立邮件服务器的账号
[root@mail ~]# groupadd -g 2013 postfix
[root@mail ~]# groupadd -g 2014 postdrop
[root@mail ~]# useradd -g postfix -u 2013 -s /sbin/nologin -M postfix
安装postfix
shell>tar -zxvf postfix-2.8.2.tar.gz -C /usr/local/src
shell>cd /usr/local/src/postfix-2.8.2
shell>make makefiles'CCARGS=-DHAS_MYSQL
-I /usr/include/mysql/ -DUSE_SASL_AUTH-DUSE_TLS-DUSE_CYRUS_SASL
-I /usr/include/sasl'
'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 -lssl -lcrypto '
Shell>make && make install
install_root: [/]
tempdir: [/usr/local/src/postfix-2.8.2] /tmp (自选)
config_directory: [/etc/postfix]
command_directory: [/usr/sbin]
daemon_directory: [/usr/libexec/postfix]
data_directory: [/var/lib/postfix]
html_directory: [no] /usr/local/apache/postfix(自选)
提取postfix-rpm中的脚本
shell> mkdir /script
shell>cp /mnt/cdrom/Server/postfix-2.3.3-2.1.el5_2.i386.rpm /script
shell>cd /script/
shell>rpm2cpio postfix-2.3.3-2.1.el5_2.i386.rpm |cpio -id
shell>cp -p /script/etc/rc.d/init.d/postfix /etc/init.d/
shell>ln -s /usr/local/postfix/include /usr/include/postfix
shell>vim /etc/profile
shell>vim /etc/ld.so.conf.d/postfix.conf
shell>service postfix start
shell>chkconfig postfix on
shell>vim /etc/postfix/main.cf
75 myhostname = mail.gz.com
83 mydomain = gz.com
113 inet_interfaces = all
这时如果没有问题就可以使用telnet 127.0.0.1 25 测试发信再用mail命令接受信件
postfix验证
Postfix结合mysql验证需要一个smtpd.conf的文件
shell> cd /usr/lib/sasl2
shell> cp -p Sendmail.conf smtpd.conf
shell> vim smtpd.conf
pwcheck_method:authdaemond
log_level:3
mech_list: PLAIN LOGIN
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
shell> service saslauthd start
shell> chkconfig saslauthd on
安装courier-authlib结合mysql数据库实现验证
shell> tar -jxvf courier-authlib-0.63.0.tar.bz2 -C /usr/local/src/
shell> cd /usr/local/src/courier-authlib-0.63.0/
./configure \
--prefix=/usr/local/courier-authlib \
--sysconfdir=/etc \
--with-authmysql \
--with-mysql-libs=/usr/lib/mysql \ #mysql库文件位置
--with-mysql-includes=/usr/include/mysql \
--with-redhat \#针对redhat系统进行优化
--with-authmysqlrc=/etc/authmysqlrc \ 访问数据库的哪个表以什么身份访问写在suthmysqlrc
--with-authdaemonrc=/etc/authdaemonrc \验证时的模块
--with-ltdl-lib=/usr/lib \
--with-ltdl-include=/usr/include
shell> make && make install
shell> chmod 755 /usr/local/courier-authlib/var/spool/authdaemon/
shell> cp -p /etc/authdaemonrc.dist /etc/authdaemonrc
shell> cp -p /etc/authmysqlrc.dist /etc/authmysqlrc
shell> vim /etc/authdaemonrc
27 authmodulelist="authmysql"
34 authmodulelistorig="authmysql"
shell> vim /etc/authmysqlrc
26 MYSQL_SERVER localhost
27 MYSQL_USERNAME extmail
28 MYSQL_PASSWORD extmail
49 MYSQL_SOCKET /tmp/mysql.sock
56 MYSQL_PORT 3306
68 MYSQL_DATABASE extmail
83 MYSQL_USER_TABLE mailbox
92 MYSQL_CRYPT_PWFIELD password
103 DEFAULT_DOMAIN gz.com
111 MYSQL_UID_FIELD '2013'
117 MYSQL_GID_FIELD '2013'
126 MYSQL_LOGIN_FIELD username
131 MYSQL_HOME_FIELD concat('/var/mailbox',homedir)
137 MYSQL_NAME_FIELD username
148 MYSQL_MAILDIR_FIELD concat('/var/mailbox',maildir)
shell>cp -p/usr/local/src/courier-authlib-0.63.0/courier-authlib.sysvinit /etc/init.d/courier-authlib
shell> chmod a+x /etc/init.d/courier-authlib
shell>vim /etc/postfix/main.cf (在最后面添加以下内容)
############################CYRUS-SASL############################
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!
shell> service courier-authlib start
dovecot验证
shell>vim /etc/dovecot.conf
211 mail_location = maildir:/var/mailbox/%d/%n/Maildir
869 passdb sql {
871 args = /etc/dovecot-mysql.conf
872 }
930 userdb sql {
932 args = /etc/dovecot-mysql.conf
933 }
shell>vim /etc/dovecot-mysql.conf (这个文件没有需要自己创建)
1 driver = mysql
2 connect = host=/tmp/mysql.sock
3 default_pass_scheme = CRYPT
4 password_query = SELECT username AS user,password AS password FROM mailbox WHERE username = '%u'
5 user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox WHERE username = '%u'
建设站点 导入数据库 配置虚拟域
建设站点
shell> mkdir -pv /var/mailbox
mkdir: created directory `/var/mailbox'
shell> chown -R postfix /var/mailbox
shell>mkdir -pv /var/www/extsuite
shell>tar zxvf extmail-1.2.tar.gz -C /var/www/extsuite/
shell>tar zxvf extman-1.1.tar.gz -C /var/www/extsuite/
shell>cd /var/www/extsuite/
shell>mv extmail-1.2 extmail
shell>mv extman-1.1 extman
修改extmail和extman目录下cgi的所有者和所有组
修改相关文件的所有者和所属组,并修改webmail.cf配置文件和wenman.cf
shell>cd /var/www/extsuite/extmail/
shell>chown -R postfix:postfix cgi/
shell>cp -p webmail.cf.default webmail.cf
shell>vim webmail.cf
SYS_USER_LANG = zh_CN
SYS_MAILDIR_BASE = /var/mailbox
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
SYS_MYSQL_HOST = localhost
SYS_MYSQL_TABLE = mailbox
SYS_MYSQL_ATTR_USERNAME = username
SYS_MYSQL_ATTR_DOMAIN = domain
SYS_MYSQL_ATTR_PASSWD = password
SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket
shell>cd /var/www/extsuite/extman/
shell>chown -R postfix:postfix cgi/
shell>cp webmail.cf.default webmail.cf
shell>cp webman.cf.default webman.cf
SYS_MAILDIR_BASE = /var/mailbox
SYS_CAPTCHA_ON = 0
修改httpd的配置文件
shell>vim /etc/httpd/httpd.conf
LoadModule cgid_module modules/mod_cgid.so
User postfix
Group postfix
<Directory "/var/www/extsuite/extmail">
AllowOverride None
Options Indexes FollowSymlinks
Require all granted
</Directory>
<Directory "/var/www/extsuite/extman">
AllowOverride None
Options Indexes FollowSymlinks
Require all granted
</Directory>
<VirtualHost 10.3.1.100:80>
ServerName mail.gz.com
DocumentRoot /var/www/extsuite/extmail/html/
ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
Alias /extmail /var/www/extsuite/extmail/html
ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
Alias /extman /var/www/extsuite/extman/html
</Virtualhost>
导入数据库并初始化和授权
shell>cd /var/www/extsuite/extman/docs/
shell>mysql -uroot -p <extmail.sql
使用rpm包安装mysql-server不需要修改extmail.sql,是源码安装的mysqlserver需要修改此文件
需要修改四项
1:添加字段
INSERT INTO user (Host, User,Password,ssl_cipher,x509_issuer,x509_subject) VALUES
('localhost','extmail',password('extmail'),'Y','Y','Y');
INSERT INTO user (Host, User, Password,ssl_cipher,x509_issuer,x509_subject) VALUES
('localhost','webman',password('webman'),'Y','Y','Y');
2:将指定的数据引擎删除 TYPE=MyISAM COMMENT='ExtMail - Virtual Aliases',不要把最后的分号也删了
3:将文本类型的默认为空删除
例如 question text NOT NULL default '',改为question text NOT NULL default '',
4:将 can_signup tinyint(1) NOT NULL default '0', 改为can_signup varchar(22) NOT NULL default '0',
shell>mysql -uroot -p <init.sql
mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail';
mysql> GRANT all privileges on extmail.* TO [email protected] IDENTIFIED BY 'extmail';
mysql>FLUSH PRIVILEGES; 让设置的内容生效
使邮件服务器支持虚拟域
shell>cp -p /var/www/extsuite/docs/mysql* /etc/postfix
shell>vim /etc/postfix/main.cf
########################Virtual Mailbox Settings########################
virtual_mailbox_base = /var/mailbox
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_alias_domains =
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_uid_maps = static:2013
virtual_gid_maps = static:2013
virtual_transport = virtual
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit = 1
##########################QUOTA Settings########################
message_size_limit = 14336000
virtual_mailbox_limit = 20971520
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, the user's maildir has overdrawn his diskspace quota, please Tidy your mailbox and try again later.
virtual_overquota_bounce = yes
安装Unix-Syslog 不然网页不能正常显示
shell>tar -zxvf Unix-Syslog-0.100.tar.gz -C /usr/local/
shell>cd /usr/local
shell>mv Unix-Syslog-0.100/ unix-syslog
shell>cd unix-syslog/
shell>perl Makefile.PL
shell>make && make install
重启所有服务
service named restart
service mysql restart
service saslauthd restart
service courier-authlib restart
service postfix restart
service dovecot restart
service httpd restart
访问站点:http://IP/extmail 管理员登陆账号:[email protected] 密码:extmail*123*
创建域,在域中创建账号,进行发信收信验证(在创建域时允许打钩,在创建成功后需要再次确认)