歡迎您光臨本站 註冊首頁

架構基於Free BSD和Postfix虛擬域郵件系統

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

架構基於Free BSD和Postfix虛擬域郵件系統

Copyright © 2004、2005、2006、2007、2008
        本文介紹使用FreeBSD+Postfix+Mysql+cyrus-sasl+Courier-ima+Maildrop+spamassasin+clamav來架構一個具有多域名,有webmail防病毒和垃圾郵件並有web管理界面的郵件系統。
        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                        
                                                            
BZIP2     Enable Bzip2 support                           
CML       Enable Cache Meta Language support            
[ ] FAM       Enable fam/gamin support                       
[ ] GDBM      Enable gdbm storage support                    
[ ] IPV6      Enable IPV6 support                           
MAGNET    Enable magnet support                          
MEMCACHE  Enable memcached storage support               
MYSQL     Enable MYSQL support                           
[ ] OPENLDAP  Enable LDAP support                           
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                           
                                                                     
CLI        Build CLI version                                    
CGI        Build CGI version                                    
[ ] APACHE     Build Apache module                                   
[ ] DEBUG      Enable debug                                          
SUHOSIN    Enable Suhosin protection system (not for jails)      
MULTIBYTE  Enable zend multibyte support                        
[ ] IPV6       Enable ipv6 support                                   
MAILHEAD   Enable mail header patch                              
[ ] REDIRECT   Enable force-cgi-redirect support (CGI only)         
[ ] DISCARD    Enable discard-path support (CGI only)               
FASTCGI    Enable fastcgi support (CGI only)                     
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                       
BCMATH      bc style precision math functions                 
BZ2         bzip2 library support                             
CALENDAR    calendar conversion support                       
CTYPE       ctype functions                                   
CURL        CURL support                                      
[ ] DBA         dba support                                       
[ ] DBASE       dBase library support                             
DOM         DOM support                                       
[ ] EXIF        EXIF support                                      
[ ] FILEINFO    fileinfo support                                 
FILTER      input filter support                              
[ ] FRIBIDI     FriBidi support                                   
FTP         FTP support                                       
GD          GD library support                                
[ ] GETTEXT     gettext library support                           
[ ] GMP         GNU MP support                                    
HASH        HASH Message Digest Framework                     
ICONV       iconv support                                    
IMAP        IMAP support                                      
[ ] INTERBASE   Interbase 6 database support (Firebird)           
JSON        JavaScript Object Serialization support           
[ ] LDAP        OpenLDAP support                                 
MBSTRING    multibyte string support                          
MCRYPT      Encryption support                                
MHASH       Crypto-hashing support                           
[ ] MING        ming shockwave flash support                     
[ ] MSSQL       MS-SQL database support                           
MYSQL       MySQL database support                           
[ ] MYSQLI      MySQLi database support                           
NCURSES     ncurses support (CLI only)                        
[ ] ODBC        unixODBC support                                 
[ ] OPENSSL     OpenSSL support                                   
PCNTL       pcntl support (CLI only)                          
PCRE        Perl Compatible Regular Expression support        
[ ] PDF         PDFlib support (implies GD)                       
PDO         PHP Data Objects Interface (PDO)                  
PDO_SQLITE  PDO sqlite driver                                 
[ ] PGSQL       PostgreSQL database support                       
POSIX       POSIX-like functions                              
[ ] PSPELL      pspell support                                    
[ ] READLINE    readline support (CLI only)                       
[ ] RECODE      recode support                                    
SESSION     session support                                   
[ ] SHMOP       shmop support                                    
SIMPLEXML   simplexml support                                 
[ ] SNMP        SNMP support                                      
[ ] SOAP        SOAP support                                      
[ ] SOCKETS     sockets support                                   
SPL         Standard PHP Library                              
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                                      
TOKENIZER   tokenizer support                                 
[ ] WDDX        WDDX support (implies XML)                        
XML         XML support                                       
XMLREADER   XMLReader support                                 
[ ] XMLRPC      XMLRPC-EPI support                                
XMLWRITER   XMLWriter support                                 
[ ] XSL         XSL support (Implies DOM)                        
[ ] YAZ         YAZ support (ANSI/NISO Z39.50)                    
ZIP         ZIP support                                       
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                                 
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                 
AUTHDAEMOND   Enable use of authdaemon                        
LOGIN         Enable LOGIN authentication                     
PLAIN         Enable PLAIN authentication                     
CRAM          Enable CRAM-MD5 authentication                  
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                        
                                                                     
PCRE      Perl Compatible Regular Expressions                    
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     
TLS       Enable SSL and TLS support                             
[ ] BDB       Berkeley DB (choose version with WITH_BDB_VER)         
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                       
                                                               
OPENSSL      Build with OpenSSL support                     
[ ] FAM          Build in fam support for IDLE command         
[ ] DRAC         Build in DRAC support                          
TRASHQUOTA   Include deleted mails in the quota            
[ ] GDBM         Use gdbm db instead of system bdb              
[ ] IPV6         Build with IPv6 support                        
[ ] AUTH_LDAP    LDAP support                                   
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                           
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                  
                                                                  
AS_ROOT        Run spamd as root (recommended)               
SPAMC          Build spamd/spamc (not for amavisd)            
SACOMPILE      sa-compile                                    
DKIM           DKIM/DomainKeys Identified Mail               
SSL            Build with SSL support for spamd/spamc         
GNUPG          Install GnuPG (for sa-update)                  
MYSQL          Add MySQL support                              
[ ] PGSQL          Add PostreSQL support                          
RAZOR          Add Vipul's Razor support                     
SPF_QUERY      Add SPF query support                          
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
server.modules              = (
                               "mod_rewrite",
                               "mod_redirect",
                               "mod_alias",
                                "mod_access",
                               "mod_cml",
                               "mod_status",
                               "mod_fastcgi",
                               "mod_evhost",
                               "mod_compress",
                               "mod_expire",
                               "mod_secdownload",
                                "mod_accesslog" )

server.document-root        = "/usr/local/www/data/"
server.errorlog             = "/var/log/lighttpd.error.log"
index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm" )
server.event-handler = "freebsd-kqueue" # needed on OS X
mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar",
  ""              =>      "application/octet-stream",
)
accesslog.filename          = "/var/log/lighttpd.access.log"
url.access-deny             = ( "~", ".inc" )
$HTTP["url"] =~ "\.pdf$" {
  server.range-requests = "disable"
}
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
server.pid-file            = "/var/run/lighttpd.pid"
server.username            = "vmail"
server.groupname           = "vmail"
fastcgi.server             = ( ".php" =>
                               ( "localhost" =>
                                 (
                                   "socket" => "/var/run/lighttpd/php-fastcgi.socket",
                                   "bin-path" => "/usr/local/bin/php-cgi"
                                 )
                               )
                            )


配置sasl2

mail# ee /usr/local/lib/sasl2/smtpd.conf
pwcheck_method: auxprop
auxprop_plugin: sql
allowanonymouslogin: no
allowplaintext: yes
mech_list: PLAIN LOGIN
srp_mda: md5

password_format: crypt

sql_user: tmail
sql_passwd: tmail
sql_hostnames: localhost
sql_database: tmail
sql_select: select crypt from tmail_users where email='%u@%r' and smtpaccess='Y'

配置courier-authlib

mail# ee /usr/local/etc/authlib/authdaemonrc
authmodulelist="authmysql"
authmodulelistorig="authmysql"
daemons=5
authdaemonvar=/var/run/authdaemond
subsystem=mail
DEBUG_LOGIN=2
DEFAULTOPTIONS="wbnodsn=1"
LOGGEROPTS=""

mail# ee /usr/local/etc/authlib/authmysqlrc
MYSQL_SERVER            localhost
MYSQL_USERNAME          tmail
MYSQL_PASSWORD          tmail
MYSQL_PORT              0
MYSQL_OPT               0
MYSQL_DATABASE          tmail
MYSQL_USER_TABLE        tmail_users
MYSQL_CRYPT_PWFIELD     crypt
#MYSQL_CLEAR_PWFIELD    clear
MYSQL_UID_FIELD         uid
MYSQL_GID_FIELD         gid
MYSQL_LOGIN_FIELD       email
MYSQL_HOME_FIELD        homedir
MYSQL_NAME_FIELD        realname
MYSQL_MAILDIR_FIELD     maildir
MYSQL_QUOTA_FIELD       quota
MYSQL_AUXOPTIONS_FIELD  CONCAT("disableimap=",disableimap,",disablepop3=",disablepop3,",disablewebmail=",disablewebmail,",sharedgroup=",sharedgroup)
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
在結尾加入下面的內容
#-----------------New Add lines--------------------------------------------------
smtpd_recipient_limit = 15
bounce_queue_lifetime = 12h
maximal_queue_lifetime = 24h

myhostname = postfix.cn
smtp_helo_name = $myhostname

local_transport = maildrop
mailbox_transport = maildrop
#disable_dns_lookups = yes
smtpd_error_sleep_time = 0
smtpd_soft_error_limit = 10
smtpd_hard_error_limit = 20
default_process_limit = 500

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

virtual_mailbox_base  = /var/mail

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

broken_sasl_auth_clients    = yes
smtpd_sasl_auth_enable      = yes
smtpd_sasl_security_options = noanonymous

smtpd_client_restrictions =
        permit_mynetworks,
        permit_sasl_authenticated,
        check_client_access mysql:/usr/local/etc/postfix/mysql/mysql-access.cf,
        permit_auth_destination,
        reject  

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

smtpd_sender_restrictions =
        reject_non_fqdn_sender,
        reject_unknown_sender_domain,
#       reject_unknown_client,
        check_sender_access mysql:/usr/local/etc/postfix/mysql/mysql-access.cf,
        reject_sender_login_mismatch,
        reject_authenticated_sender_login_mismatch,
        reject_unauthenticated_sender_login_mismatch,
        permit

smtpd_recipient_restrictions =
        permit_mynetworks,
        check_client_access mysql:/usr/local/etc/postfix/mysql/mysql-access.cf,
        permit_sasl_authenticated,
        reject_unknown_hostname,
        reject_unknown_sender_domain,
        reject_non_fqdn_sender,
        reject_non_fqdn_recipient,
        reject_unknown_recipient_domain,
        reject_unauth_pipelining,
        reject_unauth_destination,
#       reject_rbl_client cblless.anti-spam.org.cn,
        permit


default_destination_recipient_limit  = 1
local_destination_concurrency_limit  = 1
maildrop_destination_recipient_limit = 1

message_size_limit = 104857600

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

smtpd_peername_lookup = no
smtpd_delay_reject = yes
smtpd_proxy_timeout = 180s
smtpd_helo_required = yes
strict_rfc821_envelopes = yes
《解決方案》

mail# ee /usr/local/etc/postfix/mysql/mysql-access.cf
hosts = localhost
user =  tmail
password = tmail
dbname = tmail
query = select access from tmail_access where source='%s'

mail# ee /usr/local/etc/postfix/mysql/mysql-alias.cf
hosts = localhost
user =  tmail
password = tmail
dbname = tmail
table = tmail_virtual
query = select alias from tmail_users where email = '%s'

mail# ee /usr/local/etc/postfix/mysql/mysql-autobbc-in.cf
hosts = localhost
user =  tmail
password = tmail
dbname = tmail
query = select autobbc from tmail_autobbc where email = '%s' AND come='1'

mail# ee /usr/local/etc/postfix/mysql/mysql-autobbc-out.cf
hosts = localhost
user =  tmail
password = tmail
dbname = tmail
query = select autobbc from tmail_autobbc where email = '%s' AND `out`='1'

mail# ee /usr/local/etc/postfix/mysql/mysql-autobbc.cf
hosts = localhost
user =  tmail
password = tmail
dbname = tmail
query = select autobbc from tmail_autobbc where email = '%s'

mail# ee /usr/local/etc/postfix/mysql/mysql-mydest.cf
hosts = localhost
user =  tmail
password = tmail
dbname = tmail
table = tmail_domaininfo
query = select domain from tmail_domaininfo where domain='%s' AND yesno='1'

mail# ee /usr/local/etc/postfix/mysql/mysql-smtpd-login.cf
hosts = localhost
user =  tmail
password = tmail
dbname = tmail
query = select email from tmail_users where email = '%s'

mail# ee /usr/local/etc/postfix/mysql/mysql-transport.cf
hosts = localhost
user =  tmail
password = tmail
dbname = tmail
table = tmail_domaininfo
query = select transport from tmail_domaininfo where domain = '%s'

mail# ee /usr/local/etc/postfix/mysql/mysql-virtual-gid.cf
hosts = localhost
user =  tmail
password = tmail
dbname = tmail
table = tmail_users
query = select gid from tmail_users where email = '%s'

mail# ee /usr/local/etc/postfix/mysql/mysql-virtual-maps.cf
hosts = localhost
user =  tmail
password = tmail
dbname = tmail
table = tmail_users
query = select maildir from tmail_users where email = '%s'

mail# ee /usr/local/etc/postfix/mysql/mysql-virtual-quota.cf
hosts = localhost
user = tmail
password = tmail
dbname = tmail
table = tmail_users
query = select quota from tmail_users where email='%s'

mail# ee /usr/local/etc/postfix/mysql/mysql-virtual-uid.cf
hosts = localhost
user =  tmail
password = tmail
dbname = tmail
table = tmail_users
query = select uid from tmail_users where email = '%s'

mail# ee /usr/local/etc/postfix/mysql/mysql-virtual.cf
hosts = localhost
user =  tmail
password = tmail
dbname = tmail
table = tmail_virtual
query = select destination from tmail_virtual where email='%s'

mail# ee /usr/local/etc/postfix/master.cf
註釋掉Maildrop的行,並修改成下面的參數
maildrop  unix  -       n       n       -       -       pipe
  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

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

你的郵箱空間已到90%,如果你想正常使用,請從你的郵箱清除一些郵件.

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

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

rewrite_header Subject
report_safe 0
required_score 10.0
use_bayes 1
bayes_auto_learn 1



配置maildroprc規則
mail# cat /usr/local/etc/maildroprc
#logfile "/var/log/maildrop.log"
SENDER="$5"
DOMAIN="$4"

USERS="$3"
USER=$USERS@$DOMAIN
#$LOGNAME
#`echo $LOGNAME >> /tmp/sender`
#`echo $SENDER >> /tmp/sender`

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

#blacklist
`/bin/test -f $HOME/.blacklist`
if ($RETURNCODE==0)
{
    if ($SENDER ne '' && lookup($SENDER, '.blacklist'))
    {
    `/usr/local/bin/maildirmake -f Spamd "$DEFAULT"`
    to $HOME/Maildir/.Spamd/
    }
}

#whitelist
`/bin/test -f $HOME/.whitelist`
if ($RETURNCODE==0)
{
    if ($SENDER ne '' && lookup($SENDER, '.whitelist'))
    {
       to $HOME/Maildir/
    }
}
  
if ($SIZE < 102400)
{
    exception {
#       xfilter "/usr/local/bin/spamassassin --prefspath=$HOME/user_prefs"
       xfilter "/usr/local/bin/spamc -f -u $LOGNAME"
    }
}
else
{
    to $HOME/Maildir/
}

#垃圾郵件過濾
if (/^X-Spam-Status: Yes/ )
{
  `/usr/local/bin/maildirmake -f Spamd "$DEFAULT"`
  to $HOME/Maildir/.Spamd/
}

#病毒郵件過濾
if (`/usr/local/bin/clamscan --no-summary --stdout --unzip --unrar  - | grep -c 'FOUND'` == 1)
{
  to "./Maildir/.Spamd"
}

#自動回復
`/bin/test -f $HOME/autoreply.cf`
if ($RETURNCODE==0)
{
        exception {
                cc "| mailbot -A 'X-Sender: $FROM' -A 'From: $FROM' -m '$HOME/autoreply.cf' $SENDMAIL -t -f $FROM''"
        }
}
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
<?php

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

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




$host = "localhost";
$user = "tmail";
$dbname = "tmail";
$password = "tmail";


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

mysql_select_db($dbname,$link) or die (mysql_error());
mysql_query("set names 'GBK'");
//mysql_query(set query gbk);
?>

配置webmail
mail# ee /usr/local/www/data/mail/config/config.inc.php
$CFG_BASEPATH = "/tmp/tmail/temp";

// Mysql
define(MYSQL_HOST, 'localhost');
define(MYSQL_USER, 'tmail');
define(MYSQL_PASS, 'tmail');
define(MYSQL_DATA, 'tmail');

$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");'
dGVzdEBwb3N0Zml4LmNu

生成密碼base64編碼
mail# perl -MMIME::Base64 -e 'print encode_base64("123456");'
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
smtpd_milters = unix:/var/run/milter/milter-limit.socket

access.db資料庫文件自動生成腳本
mail# cat /usr/local/sbin/milter.php
#!/usr/local/bin/php
<?php
$access = "/etc/mail/access";
$fp = fopen($access,'w+');


$host ="localhost";
$user = "tmail";
$passwd = "tmail";
$dbname = "tmail";
$link = mysql_connect($host,$user,$passwd);


mysql_select_db($dbname,$link);


$query = "select * from tmail_users order by id desc";
$rules = mysql_query($query,$link);
while($rs = mysql_fetch_object($rules)){
$limit = "milter-limit-From:".$rs->email."      "."150/1d"."\n";
if(fwrite($fp,$limit)===FALSE){
echo "不能寫入文件。請檢查文件許可權。";
}
}
system("/usr/sbin/makemap hash /etc/mail/access < /etc/mail/access");
system("/usr/local/etc/rc.d/milter-limit.sh restart");
?>

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

把milter.php腳本加入到自動排程中去
mail# crontab -e
0 */2 * * * /usr/sbin/milter-limit.php
《解決方案》

怎麼沒有拉啊?  我是不是搶樓了?   

樓主能不能把一些可以自己設置的可變參數的配置多說明一下    也利於像我這麼菜的菜鳥  希望照葫蘆畫瓢也能明白在做什麼

[ 本帖最後由 dranshion 於 2007-12-13 22:35 編輯 ]
《解決方案》

那不是要先佔位置先喔

槍炮與玫瑰
gentoo python c/c++
《解決方案》

這樣的基於fb應用的文章應該多整理些
《解決方案》

頂上去

[火星人 ] 架構基於Free BSD和Postfix虛擬域郵件系統已經有1197次圍觀

http://coctec.com/docs/service/show-post-32342.html