# Add *****SPAM***** to the Subject header of spam e-mails#rewrite_headerSubject***SPAM***# Save spam messages as a message/rfc822 MIME attachment instead of# modifying the original message (0: off, 2: use text/plain instead)#report_safe0# Set which networks or hosts are considered 'trusted' by your mail# server (i.e. not spammers)## trusted_networks 212.17.35.# Set file-locking method (flock is not safe over NFS, but is faster)## lock_method flock# Set the threshold at which a message is considered spam (default: 5.0)#required_score5.0# Use Bayesian classifier (default: 1)#use_bayes1# Bayesian classifier auto-learning (default: 1)#bayes_auto_learn1
Amavisd-new
Not to drop spam, virus mail.
Add *** SPAM *** tag to virus mail.
21-ubuntu-default
1
2
3
4
5
6
7
8
9
10
11
12
13
# DOMAIN KEYS IDENTIFIED MAIL (DKIM)$enable_dkim_verification=1;# Don't be verbose about sending mail:@whitelist_sender_acl=qw( .$mydomain );$final_virus_destiny=D_PASS;# (defaults to D_BOUNCE)$final_banned_destiny=D_PASS;# (defaults to D_BOUNCE)$final_spam_destiny=D_PASS;# (defaults to D_REJECT)$final_bad_header_destiny=D_PASS;# (defaults to D_PASS), D_BOUNCE suggested$subject_tag_maps_by_ccat{+CC_VIRUS}=['*** SPAM *** '];$virus_admin=undef;$spam_admin=undef;
Installation
apt install spamassassin spamc
adduser spamd --disabled-login
Configuration
/etc/default/spamassassin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
OPTIONS="--create-prefs --max-children 5 --username spamd --helper-home-dir /home/spamd/ -s /home/spamd/spamd.log"# Pid file# Where should spamd write its PID to file? If you use the -u or# --username option above, this needs to be writable by that user.# Otherwise, the init script will not be able to shut spamd down.PIDFILE="/var/run/spamd.pid"# Set nice level of spamd#NICE="--nicelevel 15"# Cronjob# Set to anything but 0 to enable the cron job to automatically update# spamassassin's rules on a nightly basisCRON=1
/etc/spamassassin/local.cf
1
2
3
4
5
6
7
8
# Add *****SPAM***** to the Subject header of spam e-mailsrewrite_header Subject *** SPAM ***
# Set the threshold at which a message is considered spam (default: 5.0)required_score 5.0
# Use Bayesian classifier (default: 1)use_bayes 1
/etc/postfix/master.cf
1
2
3
4
5
smtp inet n - n - - smtpd
-o content_filter=spamassassin
spamassassin unix - n n - - pipe
user=spamd argv=/usr/bin/spamc -f -e
/usr/sbin/sendmail -oi -f ${sender}${recipient}
Testing
IMAP
openssl s_client -crlf -connect mail.15.nasa:993
tag login ta@15.nasa 2V73wQpvTgwBGZPQscSsSnPU7nDYA9QP
tag LIST "" "*"
tag SELECT INBOX
tag STATUS INBOX (MESSAGES)
tag FETCH 16 (BODY[HEADER])
tag FETCH 5 (BODY)
Trouble-Shooting
Postfix
Differences between smtpd_relay_restrictions and smtpd_sender_restrictions
reject_sender_login_mismatch shouldn’t apply on the relay restriction.
We don’t have capability to restrict external user
Dovecot
Cannot drop user privilege of virtual user
Failed to initialize user: Couldn't drop privileges: User is missing UID (see mail_uid setting)
Setting both Uid and Gid
Failed to initialize user: Mail access for users with UID 8 not permitted (see first _valid_uid in config file, uid from mail_uid setting).
Configure first_valid_uid (default=500) to meet the target uid uid(mail) == 8.
Can’t expand for mail root dir
1
2
Failed to initialize user: Namespace '': Home directory not set for user. Can't expa
nd ~/ for mail root dir in: ~/mail:INBOX=/var/mail/ta