第9999章最佳邮件服务器方案9.1安装所有相关软件9.1.1安装服务器软件$sudoapt-getinstallpostfix-mysqlmysql-serverdovecot-pop3ddovecot-imapdamavisd-newlibclass-dbi-mysql-perlNewpasswordfortheMySQLrootuser:--------输入密码RepeatpasswordfortheMySQLrootuser:--------再次输入密码Createdirectoriesforweb-basedadministration?--------选择NoNoNoNoGeneraltypeofmailconfiguration:--------选择InternetInternetInternetInternetSiteSiteSiteSiteSystemmailname:--------输入DNSDNSDNSDNS全名(ubox.mytest.comubox.mytest.comubox.mytest.comubox.mytest.com)SSLcertificaterequired--------选择OkOkOkOkWebservertoreconfigureautomatically:--------选择apache2apache2apache2apache29.1.2安装内容过滤软件$sudoapt-getinstallSpamAssassinclamav-daemonrazorpyzorcpioarjzoonomarchlzopcabextractpaxlhaunrar9.1.3安装其他软件$sudoapt-getinstallsquirrelmailsquirrelmail-localesphp5-imap$sudoapt-getinstallopenssl$sudoapt-getinstallphpmyadmintelnetmuttmailx最佳方案1429.2为Postfix准备数据库9.2.1创建数据库maildb$mysql-uroot-pmysqlcreatedatabasemaildb;mysqlGRANTSELECT,INSERT,UPDATE,DELETEONmaildb.*TO'mailadmin'@'localhost'IDENTIFIEDBY'mailadminPassword';mysqlGRANTSELECT,INSERT,UPDATE,DELETEONmaildb.*TO'mailadmin'@'localhost.localdomain'IDENTIFIEDBY'mailadminPassword';mysqlFLUSHPRIVILEGES;9.2.2为数据库maildb创建数据表mysqlusemaildb;1.创建虚拟域表virtual_domainsmysqlCREATETABLE`virtual_domains`(idINTNOTNULLAUTO_INCREMENTPRIMARYKEY,nameVARCHAR(50)NOTNULL)TYPE=MyISAM;mysqlINSERTINTOvirtual_domains(name)VALUES('mytest.com'),('dongyouji.cn');2.创建虚拟用户表virtual_usersmysqlCREATETABLE`virtual_users`(idint(11)NOTNULLAUTO_INCREMENTPRIMARYKEY,domain_idINT(11)NOTNULL,userVARCHAR(40)NOTNULL,passwordVARCHAR(32)NOTNULL,quotaINT(10)DEFAULT'102400',CONSTRAINTUNIQUE_EMAILUNIQUE(domain_id,user),FOREIGNKEY(domain_id)REFERENCESvirtual_domains(id)ONDELETECASCADE)TYPE=MyISAM;mysqlINSERTINTOvirtual_users(domain_id,user,password,quota)VALUES(1,'bajie',MD5('bajiePassword'),10240),第9章最佳邮件服务器方案143(1,'wukong',MD5('wukongPassword'),102400),(2,'tangseng',MD5('tangsengPassword'),1048576),(1,'spams',MD5('spamsPassword'),1024);3.创建别名表virtual_aliasesmysqlCREATETABLE`virtual_aliases`(idint(11)NOTNULLAUTO_INCREMENTPRIMARYKEY,domain_idINT(11)NOTNULL,sourceVARCHAR(40)NOTNULL,destinationVARCHAR(80)NOTNULL,FOREIGNKEY(domain_id)REFERENCESvirtual_domains(id)ONDELETECASCADE)TYPE=MyISAM;最佳方案144mysqlINSERTINTOvirtual_aliases(domain_id,source,destination)VALUES(2,'tangseng','tang.sanzang@gmail.com'),(1,'bajie','bajie@mytest.com'),(1,'bajie','zhu_bajie@yahoo.com'),(1,'','spams@mytest.com');9.2.3为数据库maildb创建视图mysqlSELECTCONCAT(virtual_users.user,'@',virtual_domains.name)ASemail,virtual_users.passwordFROMvirtual_usersLEFTJOINvirtual_domainsONvirtual_users.domain_id=virtual_domains.id;+-----------------------+----------------------------------+|email|password|+-----------------------+----------------------------------+|bajie@mytest.com|00e28675230f4c9b16666098941e5d6d||wukong@mytest.com|407dbf9a4ca5a9906332ff0ea9c330fb||tangseng@dongyouji.cn|3dbc34bca13af30ed7aa2769ee468b40||spams@mytest.com|946bfb68686ed81aa5b0c58bb2633175|+-----------------------+----------------------------------+1.创建用户视图view_usersmysqlCREATEVIEWview_usersASSELECTCONCAT(u.user,'@',virtual_domains.name)ASemail,u.passwordFROMvirtual_usersuLEFTJOINvirtual_domainsONu.domain_id=virtual_domains.id;mysqlSELECT*FROMview_usersWHEREemailLIKE'bajie%';+------------------+----------------------------------+|email|password|+------------------+----------------------------------+|bajie@mytest.com|00e28675230f4c9b16666098941e5d6d|+------------------+----------------------------------+2.创建别名视图view_virtual_aliasesmysqlCREATEVIEWview_aliasesASSELECTCONCAT(virtual_aliases.source,'@',virtual_domains.name)ASemail,destinationFROMvirtual_aliasesLEFTJOINvirtual_domainsONvirtual_aliases.domain_id=virtual_domains.id;mysqlSELECT*FROMview_aliases;+---------------------+------------------------+第9章最佳邮件服务器方案145|email|destination|+---------------------+------------------------+|tangseng@mytest.com|tang.sanzang@gmail.com||bajie@mytest.com|bajie@mytest.com||bajie@mytest.com|zhu_bajie@yahoo.com||@mytest.com|spams@mytest.com|+---------------------+------------------------+9.3配置Postfix9.3.1Postfix与MySQL的关联配置$sudomkdir/etc/postfix/mysql/1.虚拟域virtual_mailbox_domains配置$sudonano/etc/postfix/mysql/domains.cfuser=mailadminpassword=mailadminPasswordhosts=127.0.0.1dbname=maildbquery=SELECT1FROMvirtual_domainsWHEREname='%s'$sudopostconf-evirtual_mailbox_domains=mysql:/etc/postfix/mysql/domains.cf$postmap-qmytest.commysql:/etc/postfix/mysql/domains.cf1postmap:warning:connecttomysqlserver127.0.0.1:Accessdeniedforuser'mailadmin'@'localhost'(usingpassword:YES)postmap:warning:connecttomysqlserver127.0.0.1:Can'tconnecttoMySQLserveron'127.0.0.1'bind-address=127.0.0.12.信箱映射virtual_mailbox_maps配置$sudonano/etc/postfix/mysql/mailbox-maps.cfuser=mailadmin最佳方案146password=mailadminPasswordhosts=127.0.0.1dbname=maildbquery=SELECT1FROMview_usersWHEREemail='%s'$postmap-qbajie@mytest.commysql:/etc/postfix/mysql/mailbox-maps.cf1$sudopostconf-evirtual_mailbox_maps=