Code Monkey home page Code Monkey logo

docker-postfix's Introduction

docker-postfix

Run postfix with SMTP authentication (sasldb) in a Docker container.
TLS and OpenDKIM support is optional. Fail2ban can be enabled.

Installation

  1. Pull image

    docker pull danilsmirnov/postfix

Usage

  1. Create postfix container with smtp authentication

    docker run -p 25:25 \
    	-e MAIL_DOMAIN=example.com -e SMTP_USER=user:pwd \
    	--name postfix -d danilsmirnov/postfix
    # Set multiple user credentials: -e SMTP_USER=user1:pwd1,user2:pwd2,...,userN:pwdN
  2. Set mail host defferent from mail domain

    docker run -p 25:25 \
    	-e MAIL_DOMAIN=example.com -e MAIL_HOST=mail.example.com -e SMTP_USER=user:pwd \
    	--name postfix -d danilsmirnov/postfix
  3. Enable OpenDKIM: save your domain key mail.private in /path/to/domainkeys

    docker run -p 25:25 \
    	-e MAIL_DOMAIN=example.com -e MAIL_HOST=mail.example.com -e SMTP_USER=user:pwd \
    	-v /path/to/domainkeys:/etc/opendkim/domainkeys \
    	--name postfix -d danilsmirnov/postfix
    # Set DKIM_SELECTOR variable if not okay with default "mail" selector

    To sign more domains add their key file(s) named $DKIM_SELECTOR._domainkey.$DOMAIN.private, e.g.:

    mail._domainkey.subdomain.example.com.private
    mail._domainkey.*.example.com.private

    (Wildcard subdomain refers to its parent domain's DNS record.)

  4. Enable TLS(587): save your SSL certificates mail.example.com.key and mail.example.com.crt to /path/to/certs

    docker run -p 587:587 \
    	-e MAIL_DOMAIN=example.com -e MAIL_HOST=mail.example.com -e SMTP_USER=user:pwd \
    	-v /path/to/certs:/etc/postfix/certs \
    	--name postfix -d danilsmirnov/postfix
  5. Enable Fail2ban with postfix-sasl jail to ban brute-force attackers

    docker run -p 25:25 \
    	-e MAIL_DOMAIN=example.com -e MAIL_HOST=mail.example.com -e SMTP_USER=user:pwd \
    	-e FAIL2BAN=enabled --cap-add NET_ADMIN \
    	--name postfix -d danilsmirnov/postfix
    # Note: NET_ADMIN capability must be granted to the container
    # FAIL2BAN_BANTIME, FAIL2BAN_FINDTIME and FAIL2BAN_MAXRETRY could be set as well
  6. Add your custom configuration script /configure.sh

    docker run -p 25:25 \
    	-e MAIL_DOMAIN=example.com -e MAIL_HOST=mail.example.com -e SMTP_USER=user:pwd \
    	-v /path/to/script:/configure.sh \
    	--name postfix -d danilsmirnov/postfix

    E.g., add an alias to forward mail to:

    postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
    echo "mailbox@${MAIL_DOMAIN} [email protected]" > /etc/postfix/virtual
    postmap /etc/postfix/virtual

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)
  • Read the reference below to find out how to generate domain keys and add public key to the domain's DNS records

Reference

Credits

docker-postfix's People

Contributors

catatnight avatar danil-smirnov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

docker-postfix's Issues

How to get the host's cron to use this?

Firstly thanks for this, I found your image super helpful in moving to a dockerised postfix.

I was wondering if you had any ideas for how to get cron on the host machine to use this? I've got ports 25 and 587 mapped to the host, but cron seems to want a sendmail command, which is normally provided by postfix. It seems crazy and potentially very confusing to install postfix on the host machine just to get sendmail, and it's going to conflict with the mapped ports.

I tried minimalist options like msmtp but then I end up with bare or invalid from headers like From: root or From: root (Cron Daemon) and the mail gets rejected.

Do you have any suggestions for how to set this up sanely?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.