Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ build:
run:
# Copy test files
cp test/accounts.cf postfix/
cp test/main.cf postfix/
cp test/virtual postfix/
# Run containers
docker run -d --name mail \
Expand All @@ -18,6 +19,7 @@ run:
-e SA_TAG=1.0 \
-e SA_TAG2=2.0 \
-e SA_KILL=3.0 \
-e SASL_PASSWD=testing \
-h mail.my-domain.com -t $(NAME)
docker run -d --name mail_pop3 \
-v "`pwd`/postfix":/tmp/postfix \
Expand All @@ -36,11 +38,11 @@ run:

fixtures:
# Sending test mails
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/test/email-templates/amavis-spam.txt"
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/test/email-templates/amavis-virus.txt"
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/test/email-templates/existing-alias-external.txt"
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/test/email-templates/existing-alias-local.txt"
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/test/email-templates/existing-user.txt"
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/test/email-templates/amavis-spam.txt"
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/test/email-templates/amavis-virus.txt"
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/test/email-templates/existing-alias-external.txt"
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/test/email-templates/existing-alias-local.txt"
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/test/email-templates/existing-user.txt"
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/test/email-templates/non-existing-user.txt"
# Wait for mails to be analyzed
sleep 10
Expand All @@ -51,6 +53,6 @@ tests:

clean:
# Get default files back
git checkout postfix/accounts.cf postfix/virtual
git checkout postfix/accounts.cf postfix/main.cf postfix/virtual
# Remove running test containers
docker rm -f mail mail_pop3 mail_smtponly
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ Example:
* *6.31* (default) => add 'spam detected' headers at that level
* SA_KILL
* *6.31* (default) => triggers spam evasive actions)
* SASL_PASSWORD
* *empty* (default) => No sasl_passwd will be created
* *string* => A /etc/postfix/sasl_passwd will be created with that content and postmap will be run on it

Please read [how the container starts](https://github.com/tomav/docker-mailserver/blob/master/start-mailserver.sh) to understand what's expected.

Expand Down
2 changes: 2 additions & 0 deletions postfix/master.cf
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ smtp-amavis unix - - - - 2 smtp
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
-o max_use=20
-o smtp_tls_security_level=none

127.0.0.1:10025 inet n - n - - smtpd
-o content_filter=
Expand All @@ -92,3 +93,4 @@ smtp-amavis unix - - - - 2 smtp
-o smtpd_client_connection_count_limit=0
-o smtpd_client_connection_rate_limit=0
-o receive_override_options=no_header_body_checks,no_unknown_recipient_checks
-o smtp_tls_security_level=none
3 changes: 2 additions & 1 deletion postfix/opendkim.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ UMask 002
Syslog yes
SyslogSuccess Yes
LogWhy Yes
RemoveOldSignatures Yes

Canonicalization relaxed/simple

Expand All @@ -18,4 +19,4 @@ SignatureAlgorithm rsa-sha256

UserID opendkim:opendkim

Socket inet:12301@localhost
Socket inet:12301@localhost
20 changes: 20 additions & 0 deletions start-mailserver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,26 @@ case $DMS_SSL in

esac

if [ -f /tmp/postfix/main.cf ]; then
while read line; do
postconf -e "$line"
done < /tmp/postfix/main.cf
echo "Loaded '/tmp/postfix/main.cf'"
else
echo "'/tmp/postfix/main.cf' not provided. No extra postfix settings loaded."
fi

if [ ! -z "$SASL_PASSWD" ]; then
echo "$SASL_PASSWD" > /etc/postfix/sasl_passwd
postmap hash:/etc/postfix/sasl_passwd
rm /etc/postfix/sasl_passwd
chown root:root /etc/postfix/sasl_passwd.db
chmod 0600 /etc/postfix/sasl_passwd.db
echo "Loaded SASL_PASSWORD"
else
echo "==> Warning: 'SASL_PASSWORD' is not provided. /etc/postfix/sasl_passwd not created."
fi

echo "Fixing permissions"
chown -R 5000:5000 /var/mail
mkdir -p /var/log/clamav && chown -R clamav:root /var/log/clamav
Expand Down
2 changes: 2 additions & 0 deletions test/main.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
max_idle = 600s
readme_directory = /tmp
12 changes: 12 additions & 0 deletions test/tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
[ "$status" -eq 0 ]
}

@test "checking sasl: sasl_passwd.db exists" {
run docker exec mail [ -f /etc/postfix/sasl_passwd.db ]
[ "$status" -eq 0 ]
}

#
# smtp
#
Expand Down Expand Up @@ -217,6 +222,13 @@
[ "${lines[1]}" = "otherdomain.tld" ]
}

@test "checking postfix: main.cf overrides" {
run docker exec mail grep -q 'max_idle = 600s' /tmp/postfix/main.cf
[ "$status" -eq 0 ]
run docker exec mail grep -q 'readme_directory = /tmp' /tmp/postfix/main.cf
[ "$status" -eq 0 ]
}

#
# spamassassin
#
Expand Down