需要安装的包如下:
#apt-get install postfix
#apt-get install postfix-pcre
#apt-get install dspam
1. 修改/etc/dspam/dspam.conf,修改如下
Home /var/spool/dspam
StorageDriver /usr/lib/dspam/libhash_drv.so
TrustedDeliveryAgent "/usr/sbin/sendmail"
DeliveryHost 127.0.0.1
DeliveryPort 10024
DeliveryIdent localhost
DeliveryProto SMTP
OnFail error
Trust root
Trust dspam
Trust mail
Trust mailnull
Trust smmsp
Trust daemon
Trust postfix
Trust www-data
TrainingMode teft
TestConditionalTraining on
Feature chained
Feature whitelist
Algorithm graham burton
PValue graham
Preference "spamAction=tag"
Preference "signatureLocation=headers" # ‘message‘ or ‘headers‘
Preference "showFactors=off"
AllowOverride trainingMode
AllowOverride spamAction spamSubject
AllowOverride statisticalSedation
AllowOverride enableBNR
AllowOverride enableWhitelist
AllowOverride signatureLocation
AllowOverride showFactors
AllowOverride optIn optOut
AllowOverride whitelistThreshold
HashRecMax 98317
HashAutoExtend on
HashMaxExtents 0
HashExtentSize 49157
HashMaxSeek 100
HashConnectionCache 10
Notifications off
PurgeSignatures 14 # Stale signatures
PurgeNeutral 90 # Tokens with neutralish probabilities
PurgeUnused 90 # Unused tokens
PurgeHapaxes 30 # Tokens with less than 5 hits (hapaxes)
PurgeHits1S 15 # Tokens with only 1 spam hit
PurgeHits1I 15 # Tokens with only 1 innocent hit
LocalMX 127.0.0.1
SystemLog on
UserLog on
Opt out
TrackSources spam ham
ParseToHeaders on
ChangeModeOnParse on
ChangeUserOnParse on
ServerPort 11124
ServerQueueSize 32
ServerPID /var/run/dspam/dspam.pid
ServerMode auto
ServerParameters "--deliver=innocent -d %u"
ServerIdent "localhost.localdomain"
ClientHost 127.0.0.1
ClientPort 11124
ProcessorBias on
Include /etc/dspam/dspam.d/
2. 在/etc/postfix/master.cf最后添加
# DSPAM
127.0.0.1:10024 inet n - n - - smtpd
-o smtpd_authorized_xforward_hosts=127.0.0.0/8
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_client_restrictions=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o strict_rfc821_envelopes=yes
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
dspam-retrain unix - n n - 10 pipe
flags=Ru user=dspam argv=/etc/dspam/dspam-retrain $nexthop $sender $recipient
3. 在/etc/postfix/main.cf最后添加
smtpd_client_restrictions =
check_client_access pcre:/etc/postfix/dspam_filter_access
permit_auth_destination
4. 创建/etc/postfix/transport,内容如下:
spam@pymain.pymain.net dspam-retrain:spam
ham@pymain.pymain.net dspam-retrain:innocent
5. 创建/etc/postfix/dspam_filter_access,内容如下:
/./ FILTER lmtp:[127.0.0.1]:11124
6. 创建/etc/dspam/dspam-retrain,内容如下:
# Get arguments
$class = $ARGV[0] || die; shift;
$sender = $ARGV[0] || die; shift;
$recip = $ARGV[0] || die; shift;
if ($recip =~ /^(spam|ham)-(\w+)@/) {
# username is part of the recipient
$user = $2;
} elsif ($sender =~ /^(\w+)@/) {
# username is in the sender
$user = $1;
} else {
print "Can‘t determine user\n";
exit 75; # EX_TEMPFAIL
}
# Pull out DSPAM signatures and send them to the dspam program
while (<>) {
if ((! $subj) && (/^Subject: /)) {
$subj = $_;
} elsif (/(!DSPAM:[a-f0-9]+!)/) {
open(F, "|/usr/bin/dspam --source=error --class=$class --user $user");
print F "$subj\n$1\n";
close(F);
} elsif (/(X-DSPAM-Signature: [a-f0-9]+)/) {
open(F, "|/usr/bin/dspam --source=error --class=$class --user $user");
print F "$subj\n$1\n";
close(F);
}
}
7. 修改/etc/dspam/dspam-retrain权限
#chmod +x /etc/dspam/dspam-retrain
.
TAG: postfix dspam 配置方法