Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mynetworks env variable, some cleanup #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ MAINTAINER Elliott Ye
# Set noninteractive mode for apt-get
ENV DEBIAN_FRONTEND noninteractive

# Update
RUN apt-get update

# Start editing
# Install package here for cache
RUN apt-get -y install supervisor postfix sasl2-bin opendkim opendkim-tools
RUN apt-get update && apt-get install -y \
opendkim \
opendkim-tools \
postfix \
supervisor \
sasl2-bin

# Add files
ADD assets/install.sh /opt/install.sh
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ TLS and OpenDKIM support are optional.
--name postfix -d catatnight/postfix
```

4. (Optional) Configure postfix to allow relaying from a local docker network (containers in the same network):
```
network=`docker network inspect --format='{{range .IPAM.Config}}{{.Subnet}}{{end}}' my_docker_network`

docker run -d --name smtp \
--net=my_docker_network \
-e maildomain=mydomain.localhost \
-e mynetworks=127.0.0.0/8,$network \
myrepo/postfix
```

## Note
+ Login credential should be set to (`[email protected]`, `password`) in Smtp Client
+ You can assign the port of MTA on the host machine to one other than 25 ([postfix how-to](http://www.postfix.org/MULTI_INSTANCE_README.html))
Expand Down
18 changes: 15 additions & 3 deletions assets/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ if [[ -a /etc/supervisor/conf.d/supervisord.conf ]]; then
exit 0
fi

if [ -z "$maildomain" ]; then
echo '$maildomain env variable not set, exiting'
exit 1
fi
echo "*** maildomain = $maildomain"

#supervisor
cat > /etc/supervisor/conf.d/supervisord.conf <<EOF
[supervisord]
Expand All @@ -29,6 +35,11 @@ chmod +x /opt/postfix.sh
postconf -e myhostname=$maildomain
postconf -F '*/*/chroot = n'

if [ -n "$mynetworks" ]; then
echo "*** configuring mynetworks = $mynetworks"
postconf -e mynetworks=$mynetworks
fi

############
# SASL SUPPORT FOR CLIENTS
# The following options set parameters needed by Postfix to enable
Expand All @@ -37,7 +48,7 @@ postconf -F '*/*/chroot = n'
# /etc/postfix/main.cf
postconf -e smtpd_sasl_auth_enable=yes
postconf -e broken_sasl_auth_clients=yes
postconf -e smtpd_recipient_restrictions=permit_sasl_authenticated,reject_unauth_destination
postconf -e smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
# smtpd.conf
cat >> /etc/postfix/sasl/smtpd.conf <<EOF
pwcheck_method: auxprop
Expand Down Expand Up @@ -65,7 +76,7 @@ if [[ -n "$(find /etc/postfix/certs -iname *.crt)" && -n "$(find /etc/postfix/ce
postconf -P "submission/inet/smtpd_tls_security_level=encrypt"
postconf -P "submission/inet/smtpd_sasl_auth_enable=yes"
postconf -P "submission/inet/milter_macro_daemon_name=ORIGINATING"
postconf -P "submission/inet/smtpd_recipient_restrictions=permit_sasl_authenticated,reject_unauth_destination"
postconf -P "submission/inet/smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination"
fi

#############
Expand Down Expand Up @@ -127,4 +138,5 @@ cat >> /etc/opendkim/SigningTable <<EOF
*@$maildomain mail._domainkey.$maildomain
EOF
chown opendkim:opendkim $(find /etc/opendkim/domainkeys -iname *.private)
chmod 400 $(find /etc/opendkim/domainkeys -iname *.private)
chmod 400 $(find /etc/opendkim/domainkeys -iname *.private)