Commit cada36b7 by Alin Voinea

Refs #70500 - Update documentation; Fix docker-setup.sh

parent 86615b21
# Postfix Image for SMTP Auth # Postfix SMTP only with relay support
This image is a CentOS 7 container running postfix pre-configured for SMTP relay authentication. Postfix SMTP only Docker image with SMTP relay support.
It runs as an open relay mail server inside the Docker Containers internal network,
so it can be used by any container to send emails through the remote relay.
The hostname of the postfix server is set in the environment variable `MTP_HOST` and is mandatory.
Postfix will run as an open relay server only if the variables below are also set.
The relay is set in `MTP_RELAY` and the port in `MTP_PORT`.
## Supported tags and respective Dockerfile links ## Supported tags and respective Dockerfile links
...@@ -25,40 +18,35 @@ The relay is set in `MTP_RELAY` and the port in `MTP_PORT`. ...@@ -25,40 +18,35 @@ The relay is set in `MTP_RELAY` and the port in `MTP_PORT`.
- [github.com](http://github.com/eea/eea.docker.postfix) - [github.com](http://github.com/eea/eea.docker.postfix)
## Usage
The `.secrets` file should be used as a runtime environment variables, Start postfix (to send emails using postfix within container)
to set the user and password required for SMTP authentication by the `MTP_RELAY`:
MTP_USER=user
MTP_PASS=password
Basic way to get one instance up and running:
docker run --rm -t -i -e MTP_HOST=mydomain.com --env-file=.secret -v /etc/localtime:/etc/localtime:ro --name=postfix eeacms/postfix
From the application container, running on the same docker host, one can set the SMTP server to the postfix container address. $ docker run --rm --name=postfix \
-e MTP_HOST=foo.com \
eeacms/postfix
Using the mount directive ```-v /etc/localtime:/etc/localtime:ro``` will make sure that the postfix container will share same timezone as the host, so that the emails have correct date and timestamps. or start postfix (to send emails by using a remote email server)
## Example usage $ docker run --rm --name=postfix \
-e MTP_HOST=foo.com \
-e MTP_RELAY=smtp.gmail.com \
-e MTP_USER=foo \
-e MTP_PASS=secret \
eeacms/postfix
From the postfix container ("postfix"): Start sending emails:
# from an application, python: $ docker run -it --rm --link=postfix alpine sh
$ python $ telnet postfix 25
>>> import smtplib, os HELO foo.com
>>> s = smtplib.SMTP(os.getenv('HOSTNAME')) MAIL FROM: bar@foo.com
>>> s.sendmail('test@mydomain.com', ['user@example.com'], 'test') RCPT TO: foo@bar.com
DATA
From another application container ("app"): subject: Test
Testing 1, 2, 3
docker run --rm -it -v /etc/localtime:/etc/localtime:ro --name=app --link=postfix:postfixcontainer app_image .
quit
# from an application, python:
$ python
>>> import smtplib
>>> s = smtplib.SMTP('postfixcontainer')
>>> s.sendmail('test@mydomain.com', ['user@example.com'], 'test')
## Supported environment variables ## Supported environment variables
...@@ -83,7 +71,6 @@ General Public License as published by the Free Software Foundation; ...@@ -83,7 +71,6 @@ General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later either version 2 of the License, or (at your option) any later
version. version.
## Funding ## Funding
[European Environment Agency (EU)](http://eea.europa.eu) [European Environment Agency (EU)](http://eea.europa.eu)
...@@ -9,6 +9,6 @@ postfix.service: { ...@@ -9,6 +9,6 @@ postfix.service: {
} }
console.logging: { console.logging: {
selector: "*.warn", selector: "*.info",
stdout: true stdout: true
} }
...@@ -16,25 +16,25 @@ function setup_conf_and_secret { ...@@ -16,25 +16,25 @@ function setup_conf_and_secret {
} }
if [ -z "$MTP_INTERFACES" ]; then if [ -z "$MTP_INTERFACES" ]; then
postconf -e 'inet_interfaces = all' postconf -e "inet_interfaces = all"
else else
postconf -e 'inet_interfaces = $MTP_INTERFACES' postconf -e "inet_interfaces = $MTP_INTERFACES"
fi fi
if [ ! -z "$MTP_HOST" ]; then if [ ! -z "$MTP_HOST" ]; then
postconf -e 'myhostname = $MTP_HOST' postconf -e "myhostname = $MTP_HOST"
fi fi
if [ ! -z "$MTP_DESTINATION" ]; then if [ ! -z "$MTP_DESTINATION" ]; then
postconf -e 'mydestination = $MTP_DESTINATION' postconf -e "mydestination = $MTP_DESTINATION"
fi fi
if [ ! -z "$MTP_BANNER" ]; then if [ ! -z "$MTP_BANNER" ]; then
postconf -e 'smtpd_banner = $MTP_BANNER' postconf -e "smtpd_banner = $MTP_BANNER"
fi fi
if [ ! -z "$MTP_RELAY_DOMAINS" ]; then if [ ! -z "$MTP_RELAY_DOMAINS" ]; then
postconf -e 'relay_domains = $MTP_RELAY_DOMAINS' postconf -e "relay_domains = $MTP_RELAY_DOMAINS"
fi fi
if [ ! -z "$MTP_RELAY" -a ! -z "$MTP_PORT" -a ! -z "$MTP_USER" -a ! -z "$MTP_PASS" ]; then if [ ! -z "$MTP_RELAY" -a ! -z "$MTP_PORT" -a ! -z "$MTP_USER" -a ! -z "$MTP_PASS" ]; then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment