返回列表 回复 发帖

架构基于Free BSD和Postfix虚拟域邮件系统5.5

架构基于Free BSDPostfix虚拟域邮件系统5.5


Copyright © 2004、2005、2006、2007、2008


本文介绍使用FreeBSD+Postfix+Mysql+cyrus-sasl+Courier-ima+Maildrop+spamassasin+clamav来架构一个具有多域名,有webmail防病毒和垃圾邮件并有web管理界面的邮件系统。实现发邮件数量限制。类似于163的那种,一天只能发多少封邮件。


Jacky, $Revision: 5.5 bate $Date: 2007-12-13


系统主要采用Maildrop + spamassassin + clamav来对病毒过滤和垃圾邮件过滤。


本文在5.3、5.4、5.5、6.0、6.1、6.2上安装测试通过,病毒过滤放弃采用MailScanner主要采用执行效率更高的Maildrop来对邮件过滤和垃圾邮件过滤,配置更容易,并且降低了系统开消。让系统更加稳定,经过严格病毒邮件测试成功率达到了98%。垃圾邮件过滤基本上达到了85%的成功率。

目   录
1、软件安装


1.1 系统安装

1.2 同步ports

1.3 安装MySQL

1.4 安装Lighttpd

1.5 安装PHP

1.6 安装PHP扩展

1.7 安装PHPmyadmin

1.8 安装Cyrus-sasl2

1.9 安装Postfix

1.10 安装Courier-imap

1.11 安装Maildrop

1.12 安装Spamassassin

1.13 安装clamav
1.14 安装milter-limit

2、配置系统


2.1 配置lighttpd

2.2 配置sasl2

2.3 配置courier-authlib

2.4 配置postfix

2.5 修改配额警告信息

2.6 配置spamassassin

2.7 配置maildroprc规则
2.8 配置milter-limit
2.9 access.db生成脚本

3、Webmail和webadmin安装


3.1 导入数据库

3.2 配置管理工具

3.3 配置webmail

3.4 创建目录

4、启动服务

5、测试邮件系统

5.1测试邮件收发


5.1.1 生成用户base64编码

5.1.2 生成密码base64编码

5.2 测试验证与发送

5.3 测试pop

6、Webmail截图

系统安装
FreeBSD6.2
详见安装手册
http://cnsnap.cn.freebsd.org/doc/zh_CN.GB2312/books/handbook/install.html

同步ports

mail# csup -g -L 2 -h cvsup.tw.freebsd.org /usr/share/examples/cvsup/ports-supfile

安装MySQL

mail# cd /usr/ports/databases/mysql50-server
mail# make install WITH_CHARSET=utf8 WITH_XCHARSET=all BUILD_OPTIMIZED=yes BUILD_STATIC=yes WITH_NDB=yes clean

mail# echo 'mysql_enable="YES"' >> /etc/rc.conf

mail# /usr/local/etc/rc.d/mysql-server start

安装Lighttpd
mail# pw adduser vmail -u 1003 -d /var/empty -s /sbin/nologin
mail# cd /usr/ports/www/lighttpd/
mail# make install clean

        Options for lighttpd 1.4.18_1                        


[X] BZIP2     Enable Bzip2 support                           
[X] CML       Enable Cache Meta Language support            
[ ] FAM       Enable fam/gamin support                       
[ ] GDBM      Enable gdbm storage support                    
[ ] IPV6      Enable IPV6 support                           
[X] MAGNET    Enable magnet support                          
[X] MEMCACHE  Enable memcached storage support               
[X] MYSQL     Enable MYSQL support                           
[ ] OPENLDAP  Enable LDAP support                           
[X] OPENSSL   Enable SSL support                             
[ ] VALGRIND  Enable valgrind support                 

mail# echo 'lighttpd_enable="YES"' >> /etc/rc.conf

安装PHP

mail# cd /usr/ports/lang/php5
mail# make install clean

                    Options for php5 5.2.5                           


[X] CLI        Build CLI version                                    
[X] CGI        Build CGI version                                    
[ ] APACHE     Build Apache module                                   
[ ] DEBUG      Enable debug                                          
[X] SUHOSIN    Enable Suhosin protection system (not for jails)      
[X] MULTIBYTE  Enable zend multibyte support                        
[ ] IPV6       Enable ipv6 support                                   
[X] MAILHEAD   Enable mail header patch                              
[ ] REDIRECT   Enable force-cgi-redirect support (CGI only)         
[ ] DISCARD    Enable discard-path support (CGI only)               
[X] FASTCGI    Enable fastcgi support (CGI only)                     
[X] PATHINFO   Enable path-info-check support (CGI only)            


安装PHP扩展

mail# cd /usr/ports/lang/php5-extensions
mail# make install clean


            Options for php5-extensions 1.1                       
[X] BCMATH      bc style precision math functions                 
[X] BZ2         bzip2 library support                             
[X] CALENDAR    calendar conversion support                       
[X] CTYPE       ctype functions                                   
[X] CURL        CURL support                                      
[ ] DBA         dba support                                       
[ ] DBASE       dBase library support                             
[X] DOM         DOM support                                       
[ ] EXIF        EXIF support                                      
[ ] FILEINFO    fileinfo support                                 
[X] FILTER      input filter support                              
[ ] FRIBIDI     FriBidi support                                   
[X] FTP         FTP support                                       
[X] GD          GD library support                                
[ ] GETTEXT     gettext library support                           
[ ] GMP         GNU MP support                                    
[X] HASH        HASH Message Digest Framework                     
[X] ICONV       iconv support                                    
[X] IMAP        IMAP support                                      
[ ] INTERBASE   Interbase 6 database support (Firebird)           
[X] JSON        JavaScript Object Serialization support           
[ ] LDAP        OpenLDAP support                                 
[X] MBSTRING    multibyte string support                          
[X] MCRYPT      Encryption support                                
[X] MHASH       Crypto-hashing support                           
[ ] MING        ming shockwave flash support                     
[ ] MSSQL       MS-SQL database support                           
[X] MYSQL       MySQL database support                           
[ ] MYSQLI      MySQLi database support                           
[X] NCURSES     ncurses support (CLI only)                        
[ ] ODBC        unixODBC support                                 
[ ] OPENSSL     OpenSSL support                                   
[X] PCNTL       pcntl support (CLI only)                          
[X] PCRE        Perl Compatible Regular Expression support        
[ ] PDF         PDFlib support (implies GD)                       
[X] PDO         PHP Data Objects Interface (PDO)                  
[X] PDO_SQLITE  PDO sqlite driver                                 
[ ] PGSQL       PostgreSQL database support                       
[X] POSIX       POSIX-like functions                              
[ ] PSPELL      pspell support                                    
[ ] READLINE    readline support (CLI only)                       
[ ] RECODE      recode support                                    
[X] SESSION     session support                                   
[ ] SHMOP       shmop support                                    
[X] SIMPLEXML   simplexml support                                 
[ ] SNMP        SNMP support                                      
[ ] SOAP        SOAP support                                      
[ ] SOCKETS     sockets support                                   
[X] SPL         Standard PHP Library                              
[X] SQLITE      sqlite support                                                                                   
[ ] SYBASE_CT   Sybase database support                           
[ ] SYSVMSG     System V message support                          
[ ] SYSVSEM     System V semaphore support                        
[ ] SYSVSHM     System V shared memory support                    
[ ] TIDY        TIDY support                                      
[X] TOKENIZER   tokenizer support                                 
[ ] WDDX        WDDX support (implies XML)                        
[X] XML         XML support                                       
[X] XMLREADER   XMLReader support                                 
[ ] XMLRPC      XMLRPC-EPI support                                
[X] XMLWRITER   XMLWriter support                                 
[ ] XSL         XSL support (Implies DOM)                        
[ ] YAZ         YAZ support (ANSI/NISO Z39.50)                    
[X] ZIP         ZIP support                                       
[X] ZLIB        ZLIB support                                      

安装PHPmyadmin
mail# cd /usr/ports/databases/phpmyadmin
mail# make fetch
mail# cd /usr/ports/distfiles/
mail# tar -zxf phpMyAdmin-2.11.2.2-all-languages.tar.bz2
mail# mv phpMyAdmin-2.11.2.2-all-languages /usr/local/www/data/dbadmin

浏览地址
http://192.168.138.128/dbadmin/


安装Cyrus-sasl2

mail# cd /usr/ports/security/cyrus-sasl2
mail# make install clean

             Options for cyrus-sasl 2.1.22                        


[ ] BDB           Use Berkeley DB                                 
[X] MYSQL         Use MySQL                                       
[ ] PGSQL         Use PostgreSQL                                 
[ ] SQLITE        Use SQLite                                      
[ ] DEV_URANDOM   Use /dev/urandom                                
[ ] ALWAYSTRUE    Enable the alwaystrue password verifier         
[ ] KEEP_DB_OPEN  Keep handle to Berkeley DB open                 
[X] AUTHDAEMOND   Enable use of authdaemon                        
[X] LOGIN         Enable LOGIN authentication                     
[X] PLAIN         Enable PLAIN authentication                     
[X] CRAM          Enable CRAM-MD5 authentication                  
[X] DIGEST        Enable DIGEST-MD5 authentication               
[ ] OTP           Enable OTP authentication                       
[ ] NTLM          Enable NTLM authentication                     

安装Postfix

mail# cd /usr/ports/mail/postfix
mail# make install clean

                 Options for postfix 2.4.6,1                        


[X] PCRE      Perl Compatible Regular Expressions                    
[X] SASL2     Cyrus SASLv2 (Simple Auth. and Sec. Layer)            
[ ] DOVECOT   Dovecot SASL authentication method                     
[ ] SASLKRB   If your SASL req. Kerberos select this option         
[ ] SASLKRB5  If your SASL req. Kerberos5 select this option         
[ ] SASLKMIT  If your SASL req. MIT Kerberos5 select this option     
[X] TLS       Enable SSL and TLS support                             
[ ] BDB       Berkeley DB (choose version with WITH_BDB_VER)         
[X] MYSQL     MySQL maps (choose version with WITH_MYSQL_VER)        
[ ] PGSQL     PostgreSQL maps (choose with DEFAULT_PGSQL_VER)        
[ ] OPENLDAP  OpenLDAP maps (choose ver. with WITH_OPENLDAP_VER)     
[ ] CDB       CDB maps lookups                                       
[ ] NIS       NIS maps lookups                                       
[ ] VDA       VDA (Virtual Delivery Agent)                           
[ ] TEST      SMTP/LMTP test server and generator                    


mail# echo 'sendmail_enable="NO"' >> /etc/rc.conf
mail# echo 'sendmail_submit_enable="NO"' >> /etc/rc.conf
mail# echo 'sendmail_outbound_enable="NO"' >> /etc/rc.conf
mail# echo 'sendmail_msp_queue_enable="NO"' >> /etc/rc.conf
mail# echo 'postfix_enable="YES"' >> /etc/rc.conf

安装Courier-imap

mail# cd /usr/ports/mail/courier-imap
mail# make install clean

           Options for courier-imap 4.3.0                       


[X] OPENSSL      Build with OpenSSL support                     
[ ] FAM          Build in fam support for IDLE command         
[ ] DRAC         Build in DRAC support                          
[X] TRASHQUOTA   Include deleted mails in the quota            
[ ] GDBM         Use gdbm db instead of system bdb              
[ ] IPV6         Build with IPv6 support                        
[ ] AUTH_LDAP    LDAP support                                   
[X] AUTH_MYSQL   MySQL support                                 
[ ] AUTH_PGSQL   PostgreSQL support                             
[ ] AUTH_USERDB  Userdb support                                 
[ ] AUTH_VCHKPW  Vpopmail/vchkpw support                        

mail# echo 'courier_authdaemon="YES"' >> /etc/rc.conf
mail# echo 'courier_imap_imapd_enable="YES"' >> /etc/rc.conf
mail# echo 'courier_imap_pop3d_enable="YES"' >> /etc/rc.conf
mail# chmod +x /var/run/authdaemond/

安装Maildrop

mail# cd /usr/ports/mail/maildrop
mail# make WITH_AUTHLIB=yes install clean

      Options for maildrop 2.0.4                        


[ ] AUTH_LDAP    LDAP support                           
[X] AUTH_MYSQL   MySQL support                           
[ ] AUTH_PGSQL   PostgreSQL support                     
[ ] AUTH_USERDB  Userdb support                          
[ ] AUTH_VCHKPW  Vpopmail/vchkpw support                 

安装Spamassassin

mail# cd /usr/ports/mail/p5-Mail-SpamAssassin
mail# make install clean

         Options for p5-Mail-SpamAssassin 3.2.3                  


[X] AS_ROOT        Run spamd as root (recommended)               
[X] SPAMC          Build spamd/spamc (not for amavisd)            
[X] SACOMPILE      sa-compile                                    
[X] DKIM           DKIM/DomainKeys Identified Mail               
[X] SSL            Build with SSL support for spamd/spamc         
[X] GNUPG          Install GnuPG (for sa-update)                  
[X] MYSQL          Add MySQL support                              
[ ] PGSQL          Add PostreSQL support                          
[X] RAZOR          Add Vipul's Razor support                     
[X] SPF_QUERY      Add SPF query support                          
[X] RELAY_COUNTRY  Relay country support                          

echo 'spamd_enable="YES"' >> /etc/rc.conf
echo 'spamd_flags="-m 40 -u spamd -H /var/spool/spamd"' >> /etc/rc.conf

安装clamav
mail# cd /usr/ports/security/clamav
mail# make install clean

echo 'clamav_clamd_enable="YES"' >> /etc/rc.conf
echo 'clamav_freshclam_enable="YES"' >> /etc/rc.conf

安装milter-limit
mail# cd /usr/ports/databases/db43
mail# make install clean

mail# cd /usr/ports/mail/sendmail
mail# make fetch

mail# cd /usr/ports/distfiles/
mail# tar -zxf sendmail.8.14.2.tar.gz
mail# cd sendmail-8.14.2/
mail# sh Build -c
mail# sh Build install

mail# cd /usr/home/jacky/src/com/snert/src/lib
mail# ./configure --prefix=/usr/local/snert --with-db=/usr/local/include/db43
mail# make build

mail# cd ../milter-limit
mail# ./configure --enable-run-user=postfix --enable-run-group=postfix
mail# make build
mail# make install


配置系统

配置lighttpd
mail# mkdir /usr/local/www/data/
mail# mkdir /var/run/lighttpd/
mail# chown -R vmail:vmail /var/run/lighttpd
mail# touch /var/log/lighttpd.access.log
mail# chown -R vmail:vmail /var/log/lighttpd.access.log
mail# chmod 755 /var/log/lighttpd.access.log
mail# chown vmail:vmail /var/log/lighttpd.error.log

配置文件lighttpd.conf
mail# ee /usr/local/etc/lighttpd.conf

  1. server.modules              = (
  2.                                "mod_rewrite",
  3.                                "mod_redirect",
  4.                                "mod_alias",
  5.                                 "mod_access",
  6.                                "mod_cml",
  7.                                "mod_status",
  8.                                "mod_fastcgi",
  9.                                "mod_evhost",
  10.                                "mod_compress",
  11.                                "mod_expire",
  12.                                "mod_secdownload",
  13.                                 "mod_accesslog" )

  14. server.document-root        = "/usr/local/www/data/"
  15. server.errorlog             = "/var/log/lighttpd.error.log"
  16. index-file.names            = ( "index.php", "index.html",
  17.                                 "index.htm", "default.htm" )
  18. server.event-handler = "freebsd-kqueue" # needed on OS X
  19. mimetype.assign             = (
  20.   ".pdf"          =>      "application/pdf",
  21.   ".sig"          =>      "application/pgp-signature",
  22.   ".spl"          =>      "application/futuresplash",
  23.   ".class"        =>      "application/octet-stream",
  24.   ".ps"           =>      "application/postscript",
  25.   ".torrent"      =>      "application/x-bittorrent",
  26.   ".dvi"          =>      "application/x-dvi",
  27.   ".gz"           =>      "application/x-gzip",
  28.   ".pac"          =>      "application/x-ns-proxy-autoconfig",
  29.   ".swf"          =>      "application/x-shockwave-flash",
  30.   ".tar.gz"       =>      "application/x-tgz",
  31.   ".tgz"          =>      "application/x-tgz",
  32.   ".tar"          =>      "application/x-tar",
  33.   ".zip"          =>      "application/zip",
  34.   ".mp3"          =>      "audio/mpeg",
  35.   ".m3u"          =>      "audio/x-mpegurl",
  36.   ".wma"          =>      "audio/x-ms-wma",
  37.   ".wax"          =>      "audio/x-ms-wax",
  38.   ".ogg"          =>      "application/ogg",
  39.   ".wav"          =>      "audio/x-wav",
  40.   ".gif"          =>      "image/gif",
  41.   ".jpg"          =>      "image/jpeg",
  42.   ".jpeg"         =>      "image/jpeg",
  43.   ".png"          =>      "image/png",
  44.   ".xbm"          =>      "image/x-xbitmap",
  45.   ".xpm"          =>      "image/x-xpixmap",
  46.   ".xwd"          =>      "image/x-xwindowdump",
  47.   ".css"          =>      "text/css",
  48.   ".html"         =>      "text/html",
  49.   ".htm"          =>      "text/html",
  50.   ".js"           =>      "text/javascript",
  51.   ".asc"          =>      "text/plain",
  52.   ".c"            =>      "text/plain",
  53.   ".cpp"          =>      "text/plain",
  54.   ".log"          =>      "text/plain",
  55.   ".conf"         =>      "text/plain",
  56.   ".text"         =>      "text/plain",
  57.   ".txt"          =>      "text/plain",
  58.   ".dtd"          =>      "text/xml",
  59.   ".xml"          =>      "text/xml",
  60.   ".mpeg"         =>      "video/mpeg",
  61.   ".mpg"          =>      "video/mpeg",
  62.   ".mov"          =>      "video/quicktime",
  63.   ".qt"           =>      "video/quicktime",
  64.   ".avi"          =>      "video/x-msvideo",
  65.   ".asf"          =>      "video/x-ms-asf",
  66.   ".asx"          =>      "video/x-ms-asf",
  67.   ".wmv"          =>      "video/x-ms-wmv",
  68.   ".bz2"          =>      "application/x-bzip",
  69.   ".tbz"          =>      "application/x-bzip-compressed-tar",
  70.   ".tar.bz2"      =>      "application/x-bzip-compressed-tar",
  71.   ""              =>      "application/octet-stream",
  72. )
  73. accesslog.filename          = "/var/log/lighttpd.access.log"
  74. url.access-deny             = ( "~", ".inc" )
  75. $HTTP["url"] =~ "\.pdf$" {
  76.   server.range-requests = "disable"
  77. }
  78. static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
  79. server.pid-file            = "/var/run/lighttpd.pid"
  80. server.username            = "vmail"
  81. server.groupname           = "vmail"
  82. fastcgi.server             = ( ".php" =>
  83.                                ( "localhost" =>
  84.                                  (
  85.                                    "socket" => "/var/run/lighttpd/php-fastcgi.socket",
  86.                                    "bin-path" => "/usr/local/bin/php-cgi"
  87.                                  )
  88.                                )
  89.                             )
复制代码



配置sasl2

mail# ee /usr/local/lib/sasl2/smtpd.conf

  1. pwcheck_method: auxprop
  2. auxprop_plugin: sql
  3. allowanonymouslogin: no
  4. allowplaintext: yes
  5. mech_list: PLAIN LOGIN
  6. srp_mda: md5

  7. password_format: crypt

  8. sql_user: tmail
  9. sql_passwd: tmail
  10. sql_hostnames: localhost
  11. sql_database: tmail
  12. sql_select: select crypt from tmail_users where email='%u@%r' and smtpaccess='Y'
复制代码


配置courier-authlib

mail# ee /usr/local/etc/authlib/authdaemonrc

  1. authmodulelist="authmysql"
  2. authmodulelistorig="authmysql"
  3. daemons=5
  4. authdaemonvar=/var/run/authdaemond
  5. subsystem=mail
  6. DEBUG_LOGIN=2
  7. DEFAULTOPTIONS="wbnodsn=1"
  8. LOGGEROPTS=""
复制代码


mail# ee /usr/local/etc/authlib/authmysqlrc

  1. MYSQL_SERVER            localhost
  2. MYSQL_USERNAME          tmail
  3. MYSQL_PASSWORD          tmail
  4. MYSQL_PORT              0
  5. MYSQL_OPT               0
  6. MYSQL_DATABASE          tmail
  7. MYSQL_USER_TABLE        tmail_users
  8. MYSQL_CRYPT_PWFIELD     crypt
  9. #MYSQL_CLEAR_PWFIELD    clear
  10. MYSQL_UID_FIELD         uid
  11. MYSQL_GID_FIELD         gid
  12. MYSQL_LOGIN_FIELD       email
  13. MYSQL_HOME_FIELD        homedir
  14. MYSQL_NAME_FIELD        realname
  15. MYSQL_MAILDIR_FIELD     maildir
  16. MYSQL_QUOTA_FIELD       quota
  17. MYSQL_AUXOPTIONS_FIELD  CONCAT("disableimap=",disableimap,",disablepop3=",disablepop3,",disablewebmail=",disablewebmail,",sharedgroup=",sharedgroup)
  18. MYSQL_WHERE_CLAUSE      access='y'
复制代码


配置postfix
mail# mv /usr/sbin/sendmail /usr/sbin/sendmail.OFF
mail# ln -s /usr/local/sbin/sendmail /usr/sbin/sendmail
mail# chmod 755 /usr/sbin/sendmail
mail# ee /usr/local/etc/postfix/main.cf
在结尾加入下面的内容

  1. #-----------------New Add lines--------------------------------------------------
  2. smtpd_recipient_limit = 15
  3. bounce_queue_lifetime = 12h
  4. maximal_queue_lifetime = 24h

  5. myhostname = postfix.cn
  6. smtp_helo_name = $myhostname

  7. local_transport = maildrop
  8. mailbox_transport = maildrop
  9. #disable_dns_lookups = yes
  10. smtpd_error_sleep_time = 0
  11. smtpd_soft_error_limit = 10
  12. smtpd_hard_error_limit = 20
  13. default_process_limit = 500

  14. mydestination = mysql:/usr/local/etc/postfix/mysql/mysql-mydest.cf
  15. virtual_transport_maps = mysql:/usr/local/etc/postfix/mysql/mysql-transport.cf
  16. #virtual_alias_maps = mysql:/usr/local/etc/postfix/mysql/mysql-virtual.cf
  17. virtual_alias_maps = mysql:/usr/local/etc/postfix/mysql/mysql-alias.cf
  18. recipient_bcc_maps = mysql:/usr/local/etc/postfix/mysql/mysql-autobbc-in.cf
  19. sender_bcc_maps = mysql:/usr/local/etc/postfix/mysql/mysql-autobbc-out.cf
  20. local_recipient_maps = $virtual_mailbox_maps $virtual_maps

  21. virtual_mailbox_base  = /var/mail

  22. virtual_mailbox_maps  = mysql:/usr/local/etc/postfix/mysql/mysql-virtual-maps.cf
  23. virtual_create_maildirsize = yes
  24. virtual_mailbox_extended = yes
  25. virtual_maildir_suffix = Maildir/
  26. virtual_mailbox_limit_maps = mysql:/usr/local/etc/postfix/mysql/mysql-virtual-quota.cf
  27. virtual_mailbox_limit_override = yes
  28. virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please try again later.
  29. virtual_overquota_bounce = yes
  30. virtual_uid_maps      = mysql:/usr/local/etc/postfix/mysql/mysql-virtual-uid.cf
  31. virtual_gid_maps      = mysql:/usr/local/etc/postfix/mysql/mysql-virtual-gid.cf

  32. broken_sasl_auth_clients    = yes
  33. smtpd_sasl_auth_enable      = yes
  34. smtpd_sasl_security_options = noanonymous

  35. smtpd_client_restrictions =
  36.         permit_mynetworks,
  37.         permit_sasl_authenticated,
  38.         check_client_access mysql:/usr/local/etc/postfix/mysql/mysql-access.cf,
  39.         permit_auth_destination,
  40.         reject  

  41. smtpd_sender_login_maps = mysql:/usr/local/etc/postfix/mysql/mysql-smtpd-login.cf
  42. smtpd_reject_unlisted_sender = yes

  43. smtpd_sender_restrictions =
  44.         reject_non_fqdn_sender,
  45.         reject_unknown_sender_domain,
  46. #       reject_unknown_client,
  47.         check_sender_access mysql:/usr/local/etc/postfix/mysql/mysql-access.cf,
  48.         reject_sender_login_mismatch,
  49.         reject_authenticated_sender_login_mismatch,
  50.         reject_unauthenticated_sender_login_mismatch,
  51.         permit

  52. smtpd_recipient_restrictions =
  53.         permit_mynetworks,
  54.         check_client_access mysql:/usr/local/etc/postfix/mysql/mysql-access.cf,
  55.         permit_sasl_authenticated,
  56.         reject_unknown_hostname,
  57.         reject_unknown_sender_domain,
  58.         reject_non_fqdn_sender,
  59.         reject_non_fqdn_recipient,
  60.         reject_unknown_recipient_domain,
  61.         reject_unauth_pipelining,
  62.         reject_unauth_destination,
  63. #       reject_rbl_client cblless.anti-spam.org.cn,
  64.         permit


  65. default_destination_recipient_limit  = 1
  66. local_destination_concurrency_limit  = 1
  67. maildrop_destination_recipient_limit = 1

  68. message_size_limit = 104857600

  69. #smtpd_milters = unix:/var/run/milter/milter-limit.socket
  70. smtpd_recipient_limit = 10
  71. bounce_queue_lifetime = 12h
  72. maximal_queue_lifetime = 24h

  73. smtpd_peername_lookup = no
  74. smtpd_delay_reject = yes
  75. smtpd_proxy_timeout = 180s
  76. smtpd_helo_required = yes
  77. strict_rfc821_envelopes = yes
复制代码


mail# ee /usr/local/etc/postfix/mysql/mysql-access.cf

  1. hosts = localhost
  2. user =  tmail
  3. password = tmail
  4. dbname = tmail
  5. query = select access from tmail_access where source='%s'
复制代码


mail# ee /usr/local/etc/postfix/mysql/mysql-alias.cf

  1. hosts = localhost
  2. user =  tmail
  3. password = tmail
  4. dbname = tmail
  5. table = tmail_virtual
  6. query = select alias from tmail_users where email = '%s'
复制代码


mail# ee /usr/local/etc/postfix/mysql/mysql-autobbc-in.cf

  1. hosts = localhost
  2. user =  tmail
  3. password = tmail
  4. dbname = tmail
  5. query = select autobbc from tmail_autobbc where email = '%s' AND come='1'
复制代码


mail# ee /usr/local/etc/postfix/mysql/mysql-autobbc-out.cf

  1. hosts = localhost
  2. user =  tmail
  3. password = tmail
  4. dbname = tmail
  5. query = select autobbc from tmail_autobbc where email = '%s' AND `out`='1'
复制代码


mail# ee /usr/local/etc/postfix/mysql/mysql-autobbc.cf

  1. hosts = localhost
  2. user =  tmail
  3. password = tmail
  4. dbname = tmail
  5. query = select autobbc from tmail_autobbc where email = '%s'
复制代码


mail# ee /usr/local/etc/postfix/mysql/mysql-mydest.cf

  1. hosts = localhost
  2. user =  tmail
  3. password = tmail
  4. dbname = tmail
  5. table = tmail_domaininfo
  6. query = select domain from tmail_domaininfo where domain='%s' AND yesno='1'
复制代码


mail# ee /usr/local/etc/postfix/mysql/mysql-smtpd-login.cf

  1. hosts = localhost
  2. user =  tmail
  3. password = tmail
  4. dbname = tmail
  5. query = select email from tmail_users where email = '%s'
复制代码


mail# ee /usr/local/etc/postfix/mysql/mysql-transport.cf

  1. hosts = localhost
  2. user =  tmail
  3. password = tmail
  4. dbname = tmail
  5. table = tmail_domaininfo
  6. query = select transport from tmail_domaininfo where domain = '%s'
复制代码


mail# ee /usr/local/etc/postfix/mysql/mysql-virtual-gid.cf

  1. hosts = localhost
  2. user =  tmail
  3. password = tmail
  4. dbname = tmail
  5. table = tmail_users
  6. query = select gid from tmail_users where email = '%s'
复制代码


mail# ee /usr/local/etc/postfix/mysql/mysql-virtual-maps.cf

  1. hosts = localhost
  2. user =  tmail
  3. password = tmail
  4. dbname = tmail
  5. table = tmail_users
  6. query = select maildir from tmail_users where email = '%s'
复制代码


mail# ee /usr/local/etc/postfix/mysql/mysql-virtual-quota.cf

  1. hosts = localhost
  2. user = tmail
  3. password = tmail
  4. dbname = tmail
  5. table = tmail_users
  6. query = select quota from tmail_users where email='%s'
复制代码


mail# ee /usr/local/etc/postfix/mysql/mysql-virtual-uid.cf

  1. hosts = localhost
  2. user =  tmail
  3. password = tmail
  4. dbname = tmail
  5. table = tmail_users
  6. query = select uid from tmail_users where email = '%s'
复制代码


mail# ee /usr/local/etc/postfix/mysql/mysql-virtual.cf

  1. hosts = localhost
  2. user =  tmail
  3. password = tmail
  4. dbname = tmail
  5. table = tmail_virtual
  6. query = select destination from tmail_virtual where email='%s'
复制代码


mail# ee /usr/local/etc/postfix/master.cf
注释掉Maildrop的行,并修改成下面的参数

  1. maildrop  unix  -       n       n       -       -       pipe
  2.   flags=DRhu user=vmail argv=/usr/local/bin/maildrop -w 90 -d ${user}@${nexthop} ${extension} ${recipient} ${user} ${nexthop} ${sender}
复制代码



修改配额警告信息
mail# mv /usr/local/etc/quotawarnmsg.sample /usr/local/etc/quotawarnmsg
mail# ee /usr/local/etc/quotawarnmsg


  1. X-Comment: Rename/Copy this file to quotawarnmsg, and make appropriate changes
  2. X-Comment: See deliverquota man page for more information
  3. From: 系统管理员<webmaster@postfix.cn>                                    
  4. Reply-To: webmaster@postfix.cn
  5. To: Valued Customer:;
  6. Subject: 邮件配额警告      
  7. Mime-Version: 1.0
  8. Content-Type: text/plain; charset=iso-8859-1
  9. Content-Transfer-Encoding: 7bit

  10. 你的邮箱空间已到90%,如果你想正常使用,请从你的邮箱清除一些邮件.

  11. Your mailbox on the server is now more than 90% full. So that you can continue
  12. to receive mail you need to remove some messages from your mailbox.
复制代码


配置spamassassin
mail# ee /usr/local/etc/mail/spamassassin/local.cf


  1. rewrite_header Subject [SPAM]
  2. report_safe 0
  3. required_score 10.0
  4. use_bayes 1
  5. bayes_auto_learn 1
复制代码




配置maildroprc规则
mail# cat /usr/local/etc/maildroprc

  1. #logfile "/var/log/maildrop.log"
  2. SENDER="$5"
  3. DOMAIN="$4"

  4. USERS="$3"
  5. USER=$USERS@$DOMAIN
  6. #$LOGNAME
  7. #`echo $LOGNAME >> /tmp/sender`
  8. #`echo $SENDER >> /tmp/sender`

  9. exception {
  10.   VIRUS_TAG=`/usr/local/bin/clamdscan -V`
  11.   VIRUS_TAG="$VIRUS_TAG on $HOSTNAME"
  12.   xfilter "/usr/local/bin/reformail -A 'X-Virus-Checker-Version: $VIRUS_TAG'"
  13.   xfilter "/usr/local/bin/reformail -A 'X-Virus-Status: Clean'"
  14. }

  15. #blacklist
  16. `/bin/test -f $HOME/.blacklist`
  17. if ($RETURNCODE==0)
  18. {
  19.     if ($SENDER ne '' && lookup($SENDER, '.blacklist'))
  20.     {
  21.     `/usr/local/bin/maildirmake -f Spamd "$DEFAULT"`
  22.     to $HOME/Maildir/.Spamd/
  23.     }
  24. }

  25. #whitelist
  26. `/bin/test -f $HOME/.whitelist`
  27. if ($RETURNCODE==0)
  28. {
  29.     if ($SENDER ne '' && lookup($SENDER, '.whitelist'))
  30.     {
  31.        to $HOME/Maildir/
  32.     }
  33. }
  34.   
  35. if ($SIZE < 102400)
  36. {
  37.     exception {
  38. #       xfilter "/usr/local/bin/spamassassin --prefspath=$HOME/user_prefs"
  39.        xfilter "/usr/local/bin/spamc -f -u $LOGNAME"
  40.     }
  41. }
  42. else
  43. {
  44.     to $HOME/Maildir/
  45. }

  46. #垃圾邮件过滤
  47. if (/^X-Spam-Status: Yes/ )
  48. {
  49.   `/usr/local/bin/maildirmake -f Spamd "$DEFAULT"`
  50.   to $HOME/Maildir/.Spamd/
  51. }

  52. #病毒邮件过滤
  53. if (`/usr/local/bin/clamscan --no-summary --stdout --unzip --unrar  - | grep -c 'FOUND'` == 1)
  54. {
  55.   to "./Maildir/.Spamd"
  56. }

  57. #自动回复
  58. `/bin/test -f $HOME/autoreply.cf`
  59. if ($RETURNCODE==0)
  60. {
  61.         exception {
  62.                 cc "| mailbot -A 'X-Sender: $FROM' -A 'From: $FROM' -m '$HOME/autoreply.cf' $SENDMAIL -t -f $FROM''"
  63.         }
  64. }
复制代码

Webmail和webadmin安装
导入数据库
mail# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 108
Server version: 5.0.51 FreeBSD port: mysql-server-5.0.51


Type 'help;' or '\h' for help. Type '\c' to clear the buffer.


mysql> create database mail;
Query OK, 1 row affected (0.02 sec)


mysql> CREATE USER 'tmail'@'localhost' IDENTIFIED BY 'tmail;

mysql> GRANT USAGE ON * . * TO 'tmail'@'localhost' IDENTIFIED BY 'tmail' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

mysql> GRANT ALL PRIVILEGES ON `tmail` . * TO 'tmail'@'localhost' WITH GRANT OPTION ;
mysql> quit
mysql> mysql -u tmail -ptmail tmail < tmail.sql

配置管理工具
mail# ee /usr/local/www/data/mail/webadmin/config/config.inc.php

  1. <?php

  2. define(MAILDIR,"/var/mail");

  3. define(MISC, ".misc");
  4. define(MODE,0700);
  5. $PageSize = 15;




  6. $host = "localhost";
  7. $user = "tmail";
  8. $dbname = "tmail";
  9. $password = "tmail";


  10. $link = mysql_connect($host,$user,$password) or die(mysql_error());

  11. mysql_select_db($dbname,$link) or die (mysql_error());
  12. mysql_query("set names 'GBK'");
  13. //mysql_query(set query gbk);
  14. ?>
复制代码


配置webmail
mail# ee /usr/local/www/data/mail/config/config.inc.php

  1. $CFG_BASEPATH = "/tmp/tmail/temp";

  2. // Mysql
  3. define(MYSQL_HOST, 'localhost');
  4. define(MYSQL_USER, 'tmail');
  5. define(MYSQL_PASS, 'tmail');
  6. define(MYSQL_DATA, 'tmail');

  7. $CFG_NETDISK_PATH = "/var/mail/netdisk";
复制代码


创建目录
mail# mv /var/mail /var/mail.OFF
mail# mkdir /var/mail
mail# chown -R vmail:vmail /var/mail
mail# mkdir -p /tmp/tmail/temp
mail# chown -R vmail:vmail /tmp/tmail/temp

启动服务
mail# /usr/local/etc/rc.d/postfix start
mail# /usr/local/etc/rc.d/mysql-server start
mail# /usr/local/etc/rc.d/lighttpd start
mail# /usr/local/etc/rc.d/clamav-clamd start
mail# /usr/local/etc/rc.d/clamav-freshclam start
mail# /usr/local/etc/rc.d/courier-authdaemond start
mail# /usr/local/etc/rc.d/courier-imap-imapd.sh
mail# /usr/local/etc/rc.d/courier-imap-pop3d.sh
mail# /usr/local/etc/rc.d/sa-spamd

测试邮件系统

测试邮件收发

生成用户base64编码
mail# perl -MMIME::Base64 -e 'print encode_base64("test\@postfix.cn");'
  1. dGVzdEBwb3N0Zml4LmNu
复制代码


生成密码base64编码
mail# perl -MMIME::Base64 -e 'print encode_base64("123456");'
  1. MTIzNDU2
复制代码


测试验证与发送
mail# telnet localhost 25
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.test.com.
Escape character is '^]'.
220 postfix.cn ESMTP Postfix
ehlo mail
250-postfix.cn
250-PIPELINING
250-SIZE 104857600
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
auth login
334 VXNlcm5hbWU6
dGVzdEBwb3N0Zml4LmNu
334 UGFzc3dvcmQ6
MTIzNDU2
235 2.0.0 Authentication successful
MAIL FROM:<test@postfix.cn>
250 2.1.0 Ok
RCPT TO:<test@postfix.cn>
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
SUBJECT:test


This is a test mail;


.
250 2.0.0 Ok: queued as 8DF8E1CC20
quit
221 2.0.0 Bye
Connection closed by foreign host.

测试pop

mail# telnet localhost 110
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.test.com.
Escape character is '^]'.
+OK Hello there.
user test@postfix.cn
+OK Password required.
pass 123456
+OK logged in.
list
+OK POP3 clients that break here, they violate STD53.
1 724
2 724
3 2063
4 410
.
quit
+OK Bye-bye.
Connection closed by foreign host.

配置milter-limit(达到发送邮件数量的控制)

mail# ee /usr/local/etc/postfix/main.cf | grep milter
#新加入下面的行到mail.cf文件中,重新启动postfix
  1. smtpd_milters = unix:/var/run/milter/milter-limit.socket
复制代码


access.db数据库文件自动生成脚本
mail# cat /usr/local/sbin/milter.php
#!/usr/local/bin/php

  1. <?php
  2. $access = "/etc/mail/access";
  3. $fp = fopen($access,'w+');

  4. $host ="localhost";
  5. $user = "tmail";
  6. $passwd = "tmail";
  7. $dbname = "tmail";
  8. $link = mysql_connect($host,$user,$passwd);

  9. mysql_select_db($dbname,$link);

  10. $query = "select * from tmail_users order by id desc";
  11. $rules = mysql_query($query,$link);
  12. while($rs = mysql_fetch_object($rules)){
  13. $limit = "milter-limit-From:".$rs->email."      "."150/1d"."\n";
  14. if(fwrite($fp,$limit)===FALSE){
  15. echo "不能写入文件。请检查文件权限。";
  16. }
  17. }
  18. system("/usr/sbin/makemap hash /etc/mail/access < /etc/mail/access");
  19. system("/usr/local/etc/rc.d/milter-limit.sh restart");
  20. ?>
复制代码


mail# chmod +x /usr/local/sbin/milter.php

把milter.php脚本加入到自动排程中去
mail# crontab -e
  1. 0 */2 * * * /usr/sbin/milter-limit.php
复制代码


[ 本帖最后由 jacky 于 2007-12-13 15:33 编辑 ]
附件: 您需要登录才可以下载或查看附件。没有帐号?注册
模范是沙发?
晕,错别字都出来了

楼上应该是:“莫非是沙发?!”

好。非常好!

好,非常好。
纯粹支持一下!!!楼主干的不错!
感谢老大.辛苦力作!@
老大辛苦了,全力支持老大
有apache下的吗?
辛苦了
我喜欢FreeBSD,不知道这个能不能拿来用做企业邮件服务器
返回列表
开源邮件服务器 开源邮件服务器 web 开源邮件 开源 mail 开源 邮件服务器 邮件技术 mail技术 反垃圾邮件 反垃圾mail mail投递
邮件服务器 mail服务器 开源软件 mail软件 mail服务新品牌 开源邮件服务新品牌
开源mail服务新网站 邮件服务新品牌 mail tmail mailserver 163邮件 sendmail |Linux维护|Linux代维|成都Linux维护|成都Linux代维