• Stars
    star
    109
  • Rank 308,283 (Top 7 %)
  • Language
    Shell
  • License
    MIT License
  • Created almost 9 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Postfix SMTP relay docker image

postfix-relay

Postfix SMTP relay docker image. Useful for sending email without using an external SMTP server.

Default configuration is an open relay that relies on docker networking for protection. So be careful to not expose it publicly.

Usage

docker pull mwader/postfix-relay or clone/build it yourself. Docker hub image is built for amd64, arm/v7 and arm64.

Postfix variables

Postfix configuration options can be set using POSTFIX_<name> environment variables. See Dockerfile for default configuration. You probably want to set POSTFIX_myhostname (the FQDN used by 220/HELO).

Note that POSTFIX_myhostname will change the postfix option myhostname.

You can modify master.cf using postconf with POSTFIXMASTER_ variables. All double __ symbols will be replaced with /. For example

Postfix master.cf variables

- POSTFIXMASTER_submission__inet=submission inet n - y - - smtpd

will produce

postconf -Me submission/inet="submission inet n - y - - smtpd"

Postfix lookup tables

You can also create multiline tables using POSTMAP_<filename> like this example:

environment:
  - POSTFIX_transport_maps=hash:/etc/postfix/transport
  - |
    POSTMAP_transport=gmail.com smtp
    mydomain.com relay:[relay1.mydomain.com]:587
    * relay:[relay2.mydomain.com]:587

which will generate file /etc/postfix/transport

gmail.com smtp
mydomain.com relay:[relay1.mydomain.com]:587
* relay:[relay2.mydomain.com]:587

and run postmap /etc/postfix/transport.

Relay Client Authentication

The container includes Postfix SASL authentication options that are disabled by default.

Example Basic Client PAM Auth

First, create a passwd file.

echo "myuser:"`docker run --rm mwader/postfix-relay mkpasswd -m sha-512 "mypassword"` >> passwd_file

Then mount the passwd file and add the following postfix configs via enviromental variable.

volumes:
  - /path/to/passwd_file:/etc/postfix/sasl/sasl_passwds
environment:
  - SASL_Passwds=/etc/postfix/sasl/sasl_passwds
  - POSTFIX_smtpd_sasl_auth_enable=yes
  - POSTFIX_cyrus_sasl_config_path=/etc/postfix/sasl
  - POSTFIX_smtpd_sasl_security_options=noanonymous
  - POSTFIX_smtpd_relay_restrictions=permit_sasl_authenticated,reject

OpenDKIM variables

OpenDKIM configuration options can be set using OPENDKIM_<name> environment variables. See Dockerfile for default configuration. For example OPENDKIM_Canonicalization=relaxed/simple.

Using docker run

docker run -e POSTFIX_myhostname=smtp.domain.tld mwader/postfix-relay

Using docker-compose

app:
  # use hostname "smtp" as SMTP server

smtp:
  image: mwader/postfix-relay
  restart: always
  environment:
    - POSTFIX_myhostname=smtp.domain.tld
    - OPENDKIM_DOMAINS=smtp.domain.tld

Logging

By default container only logs to stdout. If you also wish to log mail.* messages to file on persistent volume, you can do something like:

environment:
  ...
  - RSYSLOG_LOG_TO_FILE=yes
  - RSYSLOG_TIMESTAMP=yes
volumes:
  - /your_local_path:/var/log/

You can also forward log output to remote syslog server if you define RSYSLOG_REMOTE_HOST variable. It always uses UDP protocol and port 514 as default value, port number can be changed to different one with RSYSLOG_REMOTE_PORT. Default format of forwarded messages is defined by Rsyslog template RSYSLOG_ForwardFormat, you can change it to another template (section Reserved Template Names) if you wish with RSYSLOG_REMOTE_TEMPLATE variable.

environment:
  ...
  - RSYSLOG_REMOTE_HOST=my.remote-syslog-server.com
  - RSYSLOG_REMOTE_PORT=514
  - RSYSLOG_REMOTE_TEMPLATE=RSYSLOG_ForwardFormat

Advanced logging configuration

If configuration via environment variables is not flexible enough it's possible to configure rsyslog directly: .conf files in the /etc/rsyslog.d directory will be sorted alphabetically and included into the primary configuration.

Timezone

Wrong timestamps in log can be fixed by setting proper timezone. This parameter is handled by Debian base image.

environment:
  ...
  - TZ=Europe/Prague

Known issues

I see key data is not secure: /etc/opendkim/keys can be read or written by other users error messages.

Some Docker distributions like Docker for Windows and RancherOS seems to handle volume permission in way that does not work with OpenDKIM default behavior of ensuring safe permissions on private keys.

A workaround is to disable the check using a OPENDKIM_RequireSafeKeys=no environment variable.

SPF

When sending email using your own SMTP server it is probably a good idea to setup SPF for the domain you're sending from.

DKIM

To enable DKIM, specify a whitespace-separated list of domains in the environment variable OPENDKIM_DOMAINS. The default DKIM selector is "mail", but can be changed to "<selector>" using the syntax OPENDKIM_DOMAINS=<domain>=<selector>.

At container start, RSA key pairs will be generated for each domain unless the file /etc/opendkim/keys/<domain>/<selector>.private exists. If you want the keys to persist indefinitely, make sure to mount a volume for /etc/opendkim/keys, otherwise they will be destroyed when the container is removed.

DNS records to configure can be found in the container log or by running docker exec <container> sh -c 'cat /etc/opendkim/keys/*/*.txt you should see something like this:

$ docker exec 7996454b5fca sh -c 'cat /etc/opendkim/keys/*/*.txt'

mail._domainkey.smtp.domain.tld. IN	TXT	( "v=DKIM1; h=sha256; k=rsa; "
	  "p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0Dx7wLGPFVaxVQ4TGym/eF89aQ8oMxS9v5BCc26Hij91t2Ci8Fl12DHNVqZoIPGm+9tTIoDVDFEFrlPhMOZl8i4jU9pcFjjaIISaV2+qTa8uV1j3MyByogG8pu4o5Ill7zaySYFsYB++cHJ9pjbFSC42dddCYMfuVgrBsLNrvEi3dLDMjJF5l92Uu8YeswFe26PuHX3Avr261n"
	  "j5joTnYwat4387VEUyGUnZ0aZxCERi+ndXv2/wMJ0tizq+a9+EgqIb+7lkUc2XciQPNuTujM25GhrQBEKznvHyPA6fHsFheymOuB763QpkmnQQLCxyLygAY9mE/5RY+5Q6J9oDOQIDAQAB" )  ; ----- DKIM key mail for smtp.domain.tld

License

postfix-relay is licensed under the MIT license. See LICENSE for the full license text.

More Repositories

1

fq

jq for binary formats - tool, language and decoders for working with binary and text formats
Go
9,333
star
2

jqjq

jq implementation of jq
jq
480
star
3

static-ffmpeg

Multi-arch docker image with ffmpeg/ffprobe binaries built as hardened static PIE binaries with no external dependencies
Dockerfile
211
star
4

ydls

youtube-dl HTTP download and transcode service
Go
176
star
5

ansisvg

Convert ANSI to SVG
Go
72
star
6

bump

A generic version tracking and update tool
Go
60
star
7

goutubedl

Go wrapper for youtube-dl and yt-dlp
Go
58
star
8

gormstore

GORM backend for gorilla sessions
Go
51
star
9

jq-lsp

jq language server
JSONiq
46
star
10

rgen

Resource code generator for iOS inspired by Android resource handling
Objective-C
40
star
11

catgolf

cat(1) golf
36
star
12

inkmake

Makefile inspired export from SVG files using Inkscape as backend with some added smartness.
Ruby
24
star
13

php-tftpserver

TFTP server written in PHP
PHP
22
star
14

ffcat

Preview media files in the shell
Go
15
star
15

chromesthesia

Find out what song is playing in a Chrome tab
JavaScript
15
star
16

vscode-jq

jq extension for VSCode
TypeScript
13
star
17

aes-arraybuffer

JavaScript AES and CBC implementation using ArrayBuffer
JavaScript
13
star
18

docker-webdav

WebDAV and web file browser server
Go
12
star
19

flac.tcl

Probably the slowest FLAC decoder in the world
Tcl
11
star
20

disable_sendfile_vbox_linux

Go VirtualBox vboxsf sendfile bug workaround
Go
11
star
21

crxreload

Reload Chrome extension automatically when files are changed
JavaScript
10
star
22

libfa

C automata library to build, determinize, minimize, translate regexp etc
C
10
star
23

ios-misc

Misc iOS related classes
Objective-C
10
star
24

respect

Resource inspector and lint tool to help find issues with resources in Xcode projects
Objective-C
10
star
25

gtktetris

Simple GTK tetris game
C
5
star
26

appsnax

Generate wireless app distribution mainifests for iOS directly from IPA files
PHP
5
star
27

static-gm

Image with graphicsmagick binary built as hardened static PIE binaries with no external dependencies
Dockerfile
5
star
28

filtertransport

Filtering go http transport and proxy handler
Go
4
star
29

static-shaka-packager

Image with shaka-packager binary built as hardened static PIE binaries with no external dependencies
Dockerfile
4
star
30

fultracker

Erlang bittorrent tracker experiment (Inactive project)
Erlang
3
star
31

jq-dash-docset

Tools to generate jq dash docset
HTML
3
star
32

maggie

Maggie, a GNU GameBoy Emulator (Inactive project)
C
3
star
33

textfiend

TCL implementation of the hexfiend binary template API
Tcl
3
star
34

slippy

iOS puzzle game featuring the hungry non-swimmer penguin Slippy that needs your help to catch fish
Objective-C
2
star
35

homebrew-tap

wader homebrew taps
Ruby
2
star
36

gameboy-games

Archive of GameBoy games I wrote many years ago
C
2
star
37

notify

Configurable inotify based file system monitor (Inactive project)
Python
2
star
38

objcheck

an ObjC port of the QuickCheck unit test framework
Objective-C
1
star
39

rails-misc

Misc ruby on rails goodies
Shell
1
star
40

citris

Circular Tetris (Inactive project)
C
1
star
41

fuse-misc

Misc FUSE file systems, ccxfuse, fusememfs, ircfs, pipefs, tagfs and erlfuse (Inactive projects)
C
1
star
42

gae-misc

Misc Google App Engine snippets
Python
1
star
43

chrome-search-spotify

Search Spotify Chrome extension
JavaScript
1
star
44

compose-hook

git hook for running docker-compose
Shell
1
star
45

lurker

Audio silence splitter (Inactive project)
C
1
star
46

vscode-go-debug-test

Test project for custom vscode-go debug command
Go
1
star
47

app-client-macos

Experimental appsocket support for macOS
Go
1
star
48

mo-mw-test

Testing
1
star
49

firefox-all-spaces

Ugly hack to have a separate Firefox window visible on all Mac OS X spaces (workaround because afloat etc can't be used with Firefox)
Shell
1
star
50

hugo-dropbox

Docker image that serves a hugo site from dropbox
Nginx
1
star
51

htmx-dash-docset

</> htmx dash docset
Shell
1
star