本文介绍使用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来对病毒过滤和垃圾邮件过滤。
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"
)
)
)
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'
authmodulelist="authmysql"
authmodulelistorig="authmysql"
daemons=5
authdaemonvar=/var/run/authdaemond
subsystem=mail
DEBUG_LOGIN=2
DEFAULTOPTIONS="wbnodsn=1"
LOGGEROPTS=""
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'
#-----------------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
hosts = localhost
user = tmail
password = tmail
dbname = tmail
query = select access from tmail_access where source='%s'
hosts = localhost
user = tmail
password = tmail
dbname = tmail
table = tmail_virtual
query = select alias from tmail_users where email = '%s'
hosts = localhost
user = tmail
password = tmail
dbname = tmail
query = select autobbc from tmail_autobbc where email = '%s' AND come='1'
hosts = localhost
user = tmail
password = tmail
dbname = tmail
query = select autobbc from tmail_autobbc where email = '%s' AND `out`='1'
hosts = localhost
user = tmail
password = tmail
dbname = tmail
query = select autobbc from tmail_autobbc where email = '%s'
hosts = localhost
user = tmail
password = tmail
dbname = tmail
table = tmail_domaininfo
query = select domain from tmail_domaininfo where domain='%s' AND yesno='1'
hosts = localhost
user = tmail
password = tmail
dbname = tmail
query = select email from tmail_users where email = '%s'
hosts = localhost
user = tmail
password = tmail
dbname = tmail
table = tmail_domaininfo
query = select transport from tmail_domaininfo where domain = '%s'
hosts = localhost
user = tmail
password = tmail
dbname = tmail
table = tmail_users
query = select gid from tmail_users where email = '%s'
hosts = localhost
user = tmail
password = tmail
dbname = tmail
table = tmail_users
query = select maildir from tmail_users where email = '%s'
hosts = localhost
user = tmail
password = tmail
dbname = tmail
table = tmail_users
query = select quota from tmail_users where email='%s'
hosts = localhost
user = tmail
password = tmail
dbname = tmail
table = tmail_users
query = select uid from tmail_users where email = '%s'
hosts = localhost
user = tmail
password = tmail
dbname = tmail
table = tmail_virtual
query = select destination from tmail_virtual where email='%s'
maildrop unix - n n - - pipe
flags=DRhu user=vmail argv=/usr/local/bin/maildrop -w 90 -d ${user}@${nexthop} ${extension} ${recipient} ${user} ${nexthop} ${sender}
X-Comment: Rename/Copy this file to quotawarnmsg, and make appropriate changes
X-Comment: See deliverquota man page for more information
From: 系统管理员<[email protected]>
Reply-To: [email protected]
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.
rewrite_header Subject [SPAM]
report_safe 0
required_score 10.0
use_bayes 1
bayes_auto_learn 1
#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''"
}
}
<?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);
?>
$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";
dGVzdEBwb3N0Zml4LmNu
MTIzNDU2
smtpd_milters = unix:/var/run/milter/milter-limit.socket
<?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");
?>
0 */2 * * * /usr/sbin/milter-limit.php