逻辑概念
MUA
Mail User Agent,为邮件用户提供邮件编辑界面,写好邮件提交给MTA;同时它也可以把邮件从邮箱里接受过本地查看。
MTA
SMTPD可以调用smtp发送邮件给远程smtpd,从MUA到MTA是SMTP协议,MTA分检以后发现时本地邮件通过lmtp协议传送。如果是远程邮件,调用本地客户端smtp向对方服务器端传送。
MDA
对方服务器MTA(smtpd)收到邮件调用MDA(邮件投递代理)把这封邮件投递到用户的邮件。由于邮件路由过程中可能会用到不同的服务器转发,所以邮件发件人和发送主机没有必然联系
OpenRelay 开放式中继(一般都关闭开放中继)
只要经过MTA就会分检,非内部邮件就中继。
MRA
Mail Retrival Agent邮件取回代理,使用pop3协议,用户登陆MRA做身份验证通过MRA根据身份去检索相应邮箱并取回传递给用户。当然MUA也可以,只不过每次都需要ssh登陆,所以平时都是使用POP3
WebMail
开发一个MUA套件,为用户提供web界面发送邮件。
LDAP
Light Directory Access Protocol 轻量级目录访问协议,加快身份验证的速度,随着用户增多。适合于一次写入,多次读取的应用场所,LDAP目前做的最好的是windowsserver2008,AD本身就是LDAP。
功能组件
MTA
sendmail UUCP设计理念有些过时,单体结构,SUID,配置文件语法(m4编写),不容易理解
qmail
postfix 新贵 模块化设计,避免SUID,安全,跟sendmail兼容性好,投递效率相当于sendmail的4倍左右。
Exchange Windows,异步消息写作平台,必须跟AD整合起来.
SASL 认证框架,它并不负责实现认证,还需要专业级认证组件
cyrus-sasl 默认去/etc/passwd 和 /etc/shadow
courier-authlib (此时它变为服务,停掉cyrus-sasl,只是需要用cyrus-sasl的库,由此支持虚拟用户) SASL --> Mysql
MDA
procmail
maildropz
MRA 邮件取回代理(pop3或者imap4)
cyrus-imap
dovecot 自身就可以直接访问mysql,安装的时候依赖于mysql的客户端。
MUA
Outlook Express, Outlook
Foxmail
Thunderbird
Evolution
mutt(文件界面)
Webmailweb套件
Openwebmailperl
squirrelmailphp
Extmail(Extman)可以访问mysql 调用dovecot收邮件 调用postfix发邮件
EMOS, CentOS
发邮件 Postfix + SASL (courier-authlib) + Mysql
收邮件Dovecot + Mysql
webmailExtmail + Extman + httpd
部署过程
DNS
配置文件 /etc/named.rfc1912.zones zone "soulboy.com" IN { type master; file "soulboy.com.zone"; allow-update { none; }; allow-transfer { none; }; }; zone "1.168.192.in-addr.arpa" IN { type master; file "192.168.1.zone"; allow-update { none; }; allow-transfer { none; }; 正向区域文件 /var/named/soulboy.com.zone $TTL 600 @ IN SOA ns.soulboy.com. admin.soulboy.com. ( 2013090401 2H 10M 3D 1D ) IN NS ns IN MX 10 mail ns IN A 192.168.1.30 mail IN A 192.168.1.30 反向区域文件 /var/named/192.168.1.zone $TTL 600 @ IN SOA ns.soulboy.com. admin.soulboy.com. ( 2013090401 2H 10M 3D 1D ) IN NS ns.soulboy.com. 30 IN PTR ns.soulboy.com. 30 IN PTR mail.soulboy.com. ########修改权限、开机启动、主机名################### [root@localhost named]# chgrp named soulboy.com.zone [root@localhost named]# chgrp named 192.168.1.zone [root@localhost named]# chmod 640 soulboy.com.zone [root@localhost named]# chmod 640 192.168.1.zone [root@localhost named]# chkconfig --add named [root@localhost named]# chkconfig named on [root@localhost named]# vim /etc/resolv.conf nameserver 192.168.1.30 search localdomain [root@localhost named]# vim /etc/sysconfig/network NETWORKING=yes NETWORKING_IPV6=yes HOSTNAME=mail.soulboy.com GATEWAY=192.168.1.10 [root@localhost named]# hostname mail.soulboy.com [root@mail httpd]# vim /etc/hosts 192.168.1.30 mail.soulboy.com [root@mail httpd]# service httpd start Starting httpd: [ OK ] [root@mail httpd]# service named restart Starting named: [ OK ]
MYSQL
yum install perl-DBD-MySQL -y yum install mysql-server -y yum install mysql-devel -y
POSTFIX
[root@mail httpd]# service sendmail stop Shutting down sm-client: [ OK ] Shutting down sendmail: [ OK ] [root@mail httpd]# chkconfig sendmail off [root@mail httpd]# groupadd -g 2525 postfix [root@mail httpd]# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix [root@mail httpd]# groupadd -g 2526 postdrop [root@mail httpd]# useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop [root@mail httpd]# hwclock �Cs ##//将硬件时间同步到系统时间 ##开始编译(事先将postfix-2.9.6.tar.gz放入linux中) [root@mail ~]# cd /usr/local/src [root@mail src]# tar xf postfix-2.9.6.tar.gz [root@mail src]# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS ' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 -lssl -lcrypto' [root@mail src]# make && make install [root@mail src]# vim /etc/rc.d/init.d/postfix ########################脚本如下############################ #!/bin/bash # # postfix Postfix Mail Transfer Agent # # chkconfig: 2345 80 30 # description: Postfix is a Mail Transport Agent, which is the program \ # that moves mail from one machine to another. # processname: master # pidfile: /var/spool/postfix/pid/master.pid # config: /etc/postfix/main.cf # config: /etc/postfix/master.cf # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ $NETWORKING = "no" ] && exit 3 [ -x /usr/sbin/postfix ] || exit 4 [ -d /etc/postfix ] || exit 5 [ -d /var/spool/postfix ] || exit 6 RETVAL=0 prog="postfix" start() { # Start daemons. echo -n $"Starting postfix: " /usr/bin/newaliases >/dev/null 2>&1 /usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start" RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix echo return $RETVAL } stop() { # Stop daemons. echo -n $"Shutting down postfix: " /usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog stop" RETVAL=$? [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix echo return $RETVAL } reload() { echo -n $"Reloading postfix: " /usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog reload" RETVAL=$? echo return $RETVAL } abort() { /usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog abort" return $? } flush() { /usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog flush" return $? } check() { /usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog check" return $? } restart() { stop start } # See how we were called. case "$1" in start) start ;; stop) stop ;; restart) stop start ;; reload) reload ;; abort) abort ;; flush) flush ;; check) check ;; status) status master ;; condrestart) [ -f /var/lock/subsys/postfix ] && restart || : ;; *) echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status| condrestart}" exit 1 esac exit $? # END ###################修改权限添加服务列表######################## [root@mail src]# chmod +x /etc/rc.d/init.d/postfix [root@mail src]# chkconfig --add postfix [root@mail src]# chkconfig postfix on ##################修改postfix配置文件################# [root@mail ~]# vim /etc/postfix/main.cf myhostname = mail.soulboy.com ##------指定自己的邮件服务器 myorigin = $mydomain ##------自己创建的域名 mydomain = soulboy.com ##-----定义出站邮件使用的域名 mydestination = $myhostname, localhost.$mydomain, localhost, ns.$mydomain ##定义哪些域接收邮件 mynetworks = 192.168.1.0/24, 127.0.0.0/8 ##--------定义允许中继的网络 ################################################################## [root@mail src]# service postfix start [root@mail src]# useradd hadoop && echo "hadoop" |passwd --stdin hadoop
dovecot
[root@mail ~]# yum install dovecot -y [root@mail ~]# chkconfig --add dovecot [root@mail ~]# chkconfig dovecot on [root@mail ~]# service dovecot start s
cyrus-sas
[root@mail ~]# vim /etc/sysconfig/saslauthd MECH=shadow [root@mail ~]# chkconfig --add saslauthd [root@mail ~]# chkconfig saslauthd on [root@mail ~]# service saslauthd start [root@mail ~]# testsaslauthd -uhadoop -phadoop [root@mail ~]# vim /usr/lib/sasl2/smtpd.conf pwcheck_method: saslauthd mech_list: PLAIN LOGIN [root@mail ~]# 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 smtpdsmtpd_sasl_path = smtpd smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available! [root@mail ~]# service postfix restart
虚拟域、用户、webmail、webman
courier-authlib
tar jxvf courier-authlib-0.62.4.tar.bz2 cd courier-authlib-0.62.4 ./configure --prefix=/usr/local/courier-authlib \ --sysconfdir=/etc \ --without-authpam \ --without-authshadow \ --without-authvchkpw \ --without-authpgsql \ --with-authmysql \ --with-mysql-libs=/usr/lib/mysql \ --with-mysql-includes=/usr/include/mysql \ --with-redhat \ --with-authmysqlrc=/etc/authmysqlrc \ --with-authdaemonrc=/etc/authdaemonrc \ --with-mailuser=postfix \ --with-mailgroup=postfix \ --with-ltdl-lib=/usr/lib \ --with-ltdl-include=/usr/include 改socket文件的权限 [root@mail ~]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon 把生成的配置文件重新命名 [root@mail ~]# cp /etc/authdaemonrc.dist /etc/authdaemonrc [root@mail ~]# cp /etc/authmysqlrc.dist /etc/authmysqlrc 修改/etc/authdaemonrc配置文件 [root@mail ~]# vim /etc/authdaemonrc authmodulelist="authmysql" -----指明认证的模块 authmodulelistorig="authmysql" ------保留的原始模块 daemons=10 ------默认启动启动的进程个数(根据需要修改) DEBUG_LOGIN=2 vim /etc/authmysqlrc ##配置其通过mysql进行邮件帐号认证 MYSQL_SERVER localhost MYSQL_PORT 3306 -----(指定你的mysql监听的端口,这里使用默认的3306) MYSQL_USERNAME extmail ----- (这时为后文要用的数据库的所有者的用户名) MYSQL_PASSWORD extmail ----- (密码) MYSQL_SOCKET /var/lib/mysql/mysql.sock MYSQL_DATABASE extmail MYSQL_USER_TABLE mailbox MYSQL_CRYPT_PWFIELD password -----mysql中哪个字段是用户密码 MYSQL_UID_FIELD '2525' MYSQL_GID_FIELD '2525' MYSQL_LOGIN_FIELD username MYSQL_HOME_FIELD concat('/var/mailbox/',homedir) -----用户账号的家目录所在位置,虚拟用户没有家目录,homedir是变量,等同于用户名称;concat是mysql内置的函数用于将两个字符串连接起来 MYSQL_NAME_FIELD name MYSQL_MAILDIR_FIELD concat('/var/mailbox/',maildir) 提供SysV服务脚本,为服务脚本添加执行权限并且添加到服务列表,设置开机启动并启动 [root@mail ~]# cd courier-authlib-0.64.0 [root@mail courier-authlib-0.64.0]# cp courier-authlib.sysvinit /etc/rc.d/init.d/courier-authlib [root@mail courier-authlib-0.64.0]# chmod 755 /etc/init.d/courier-authlib [root@mail courier-authlib-0.64.0]# chkconfig --add courier-authlib [root@mail courier-authlib-0.64.0]# chkconfig --level 2345 courier-authlib on [root@mail courier-authlib-0.64.0]# echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf [root@mail courier-authlib-0.64.0]# service courier-authlib start Starting Courier authentication services: authdaemond
POSTFIX courier-authlib
新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户 [root@mail ~]# mkdir �Cpv /var/mailbox [root@mail ~]# chown -R postfix /var/mailbox 接下来重新配置SMTP 认证,编辑 /usr/lib/sasl2/smtpd.conf , [root@mail ~]# vim /usr/lib/sasl2/smtpd.conf ##确保其为以下内容 pwcheck_method: authdaemond log_level: 3 mech_list: PLAIN LOGIN authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket 让postfix支持虚拟域和虚拟用户 编辑/etc/postfix/main.cf, [root@mail ~]# 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:2525 virtual_gid_maps = static:2525 virtualvirtual_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 ##保存退出 使用extman源码目录下docs目录中的extmail.sql和init.sql建立数据库 [root@mail ~]# tar xf extman-1.1.tar.gz ------事先准备~ [root@mail ~]# cd extman-1.1/docs/ [root@mail docs]# mysql -u root -p < extmail.sql -----密码为空 Enter password: [root@mail docs]# mysql -u root -p <init.sql Enter password: [root@mail docs]# cp mysql* /etc/postfix/ ##//启动mysql对用户进行授权 [root@mail docs]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.0.77 Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail'; Query OK, 0 rows affected (0.00 sec) mysql> GRANT all privileges on extmail.* TO [email protected] IDENTIFIED BY 'extmail'; Query OK, 0 rows affected (0.00 sec)
dovecot
[root@mail ~]# vim /etc/dovecot.conf ##修改 mail_location = maildir:/var/mailbox/%d/%n/Maildir auth default { mechanisms = plain passdb sql { args = /etc/dovecot-mysql.conf } userdb sql { args = /etc/dovecot-mysql.conf } [root@mail ~]# vim /etc/dovecot-mysql.conf 添加 driver = mysql connect = host=localhost dbname=extmail user=extmail password=extmail default_pass_scheme = CRYPT password_query = SELECT username AS user,password AS password FROM mailbox WHERE username = '%u' user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox WHERE username = '%u' connect = host=/tmp/mysql.sock dbname=extmail user=extmail password=extmail 启动dovecot服务: [root@mail ~]# service dovecot restart Stopping Dovecot Imap: [ OK ] Starting Dovecot Imap: [ OK ]
Extmail-1.2
说明:如果extmail的放置路径做了修改,那么配置文件webmail.cf中的/var/www路径必须修改为你所需要的位置。本文使用了默认的/var/www,所以,以下示例中并没有包含路径修改的相关内容。 1、安装 [root@mail ~]# tar xf extmail-1.2.tar.gz [root@mail ~ ]# mkdir -pv /var/www/extsuite mkdir: created directory `/var/www/extsuite' [root@mail ~]# mv extmail-1.2 /var/www/extsuite/extmail [root@mail ~]# cp /var/www/extsuite/extmail/webmail.cf.default /var/www/extsuite/extmail/webmail.cf 2、修改主配置文件 [root@mail ~]# vim /var/www/extsuite/extmail/webmail.cf ##部分修改选项的说明: SYS_MESSAGE_SIZE_LIMIT = 5242880 ##用户可以发送的最大邮件 SYS_USER_LANG = en_US ##语言选项,可改作: SYS_USER_LANG = zh_CN SYS_MAILDIR_BASE = /home/domains ##此处即为您在前文所设置的用户邮件的存放目录,可改作: SYS_MAILDIR_BASE = /var/mailbox SYS_MYSQL_USER = db_user SYS_MYSQL_PASS = db_pass ##以上两句句用来设置连接数据库服务器所使用用户名、密码和邮件服务器用到的数据库,这里修改为: SYS_MYSQL_USER = extmail SYS_MYSQL_PASS = extmail ##以上用来指定验正用户登录里所用到的表,以及用户名、域名和用户密码分别对应的表中列的名称;这里默认即可 SYS_AUTHLIB_SOCKET = /var/spool/authdaemon/socket ##此句用来指明authdaemo socket文件的位置,这里修改为: SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket 3、apache相关配置 由于extmail要进行本地邮件的投递操作,故必须将运行apache服务器用户的身份修改为您的邮件投递代理的用户;本例中打开了apache服务器的suexec功能,故使用以下方法来实现虚拟主机运行身份的指定。此例中的MDA为postfix自带,因此将指定为postfix用户: ##首先在/etc/httpd/conf/httpd.conf配置文件中注释中心主机 #DocumentRoot "/var/www/html" ##然后添加以下内容 <VirtualHost *:80> ServerName mail.magedu.com DocumentRoot /var/www/extsuite/extmail/html/ ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi Alias /extmail /var/www/extsuite/extmail/html </VirtualHost> ##保存退出。 修改 cgi执行文件属主为apache运行身份用户: [root@mail ~]# chown -R postfix.postfix /var/www/extsuite/extmail/cgi/ [root@mail ~]# vim /etc/httpd/httpd.conf ##//添加如下内容 User postfix Group postfix [root@mail ~]# vim /etc/httpd/conf/httpd.conf ##//添加如下内容 <VirtualHost *:80> ServerName mail.magedu.com DocumentRoot /var/www/extsuite/extmail/html/ ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi Alias /extmail /var/www/extsuite/extmail/html </VirtualHost> 4、依赖关系的解决 extmail将会用到perl的Unix::syslogd功能,您可以去http://search.cpan.org搜索下载原码包进行安装。 [root@mail ~]# tar zxvf Unix-Syslog-1.1.tar.gz [root@mail ~]# cd Unix-Syslog-1.1 [root@mail Unix-Syslog-1.1]# perl Makefile.PL [root@mail Unix-Syslog-1.1]# make && make install 5、启动apache服务 [root@mail Unix-Syslog-1.1]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]
首先创建webman用户(在webman.cf配置文件指定的默认用户) 连接mysql创建webman [root@mail ~]# mysql mysql> GRANT ALL PRIVILEGES ON extmail.* TO webman@localhost IDENTIFIED BY 'webman'; mysql> GRANT ALL PRIVILEGES ON extmail.* TO [email protected] IDENTIFIED BY 'webman'; mysql> FLUSH PRIVILEGES; [root@mail ~]# mv extman-1.1 /var/www/extsuite/extman [root@mail ~]# cd /var/www/extsuite/extman/ [root@mail extman]# cp /var/www/extsuite/extman/webman.cf.default /var/www/extsuite/extman/webman.cf 编辑extman配置文件 [root@mail extman]# vim /var/www/extsuite/extman/webman.cf ##修改内容 SYS_MAILDIR_BASE = /var/mailbox 修改邮箱位置 SYS_CAPTCHA_ON = 0 关闭验证码模块 SYS_DEFAULT_UID = 2525 SYS_DEFAULT_GID = 2525 ##更改UID与GID(是postfixUID与其组的GID 修改完成,保存退出 创建extman运行时所需的临时目录,并修改属主属组 [root@mail extman]# mkdir /tmp/extman [root@mail extman]# chown postfix.postfix /tmp/extman 修改apache配置文件,虚拟主机定义的内容最终修改如下 ScriptAlias /extmail/cgi /var/www/extsuite/extman/cgi Alias /extman /var/www/extsuite/extmail/html 修改cgi目录的属主数组为postfix [root@mail extman]# vim /etc/httpd/conf/httpd.conf [root@mail extman]# chown -R postfix.postfix /var/www/extsuite/extman/cgi 修改完成后保存退出 重新启动apache服务 [root@mail extman]# service httpd restart
测试
本文出自 “星矢” 博客,转载请与作者联系!