Simple mail relay server built with Postfix and OpenDKIM
405
A mail relay server. When you send mail to this container, it forwards the mail externally with a DKIM signature, depending on the sender domain. Multiple domains supported. The DKIM selector is fixed to default.
GitHub repository is here. Japanese document is here.
Since logs are output to standard output, you can check them with docker logs or docker compose logs.
Two types of log files are output:
$ mkdir -p logs/list
$ mkdir -p logs/raw
$ chmod 777 logs/list logs/raw
or
$ chown YOUR-USER-WHOSE-ID-IS-1000 logs/list logs/raw
$ mkdir keys
Create DKIM public/private keys using the opendkim-genkey command and put them into the keys/ directory. You can store keys for multiple domains.
The filename should be in the format FQDN + .private, such as example.com.private.
Register the public key in your DNS TXT record. Since DKIM is verified by the recipient, you can skip this step if you are just testing.
$ dig +short txt default._domainkey.example.com
"v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0...."
$ docker run -d \
-v `pwd`/keys/:/keys/ \
-v `pwd`/logs/:/maillogs/ \
-e SERVERNAME=postfix.example.com \
-p 25:25 \
-p 1025:25 \
netebakari/simple-mail-relay:latest
With this configuration, the container will deliver received mail directly to the internet. I strongly advise you to first build a separate mail receiving container, forward all mail to it, and thoroughly test the setup. Refer to the GitHub repository for the procedure.
Now you can connect to port TCP/25 or TCP/1025 of localhost using TELNET or something you would like and send emails. If you write an email address of a domain with DKIM configuration completed in From, it will be signed.
$ telnet localhost 1025
HELO localhost
MAIL FROM: [email protected]
RCPT TO: [email protected]
DATA
From: [email protected]
To: [email protected]
Subject: Test
Hello World!
.
QUIT
Check the email body in logs/raw/YYYY-MM-DD/. It would be just like:
From [email protected] Fri Feb 14 20:11:54 2025
Return-Path: <[email protected]>
X-Original-To: logging@localhost
Delivered-To: logging@localhost
DKIM-Filter: OpenDKIM Filter v2.11.0 localhost C23B4466FA
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com;
s=default; t=1739596314;
bh=z85OKVJZHnmg3qFlSpLbpPCZ00irfBdrzQUtabiSl3A=;
h=From:To:Subject:From;
b=KItSmTGe5svNXMXq02JJo+p8BoJhVbX2tmVatA9I2FfMQpEc6gC9z6irv9XGQkiTe
VKCgcl1m8PMcDSskMKP0D7Y0iQkxw57BffLjCSzFL/aiDB7ZhG1XXip3KEXPfIDuq7
zp7pwBuXag/tAa1edfPab06lCDGetrPiblUkTIycltW76RltAi0dzDE3KukV/l/Nwt
e6wxWcqUDfbngJXE4GcPLk2EpvLuEL+Z41M3OTe6EM4GXgUTsklKDXKzXV8Jkyl/lC
oFiZq6f3gCAUNN9GTyI1/fljQzOHCwTNceN/OLYuc8biIs/X8qtrXPIHn22fuXe6o0
JDWeLykgVnbew==
Received: from localhost (unknown [172.17.0.1])
by localhost (Postfix) with SMTP id C23B4466FA
for <[email protected]>; Fri, 14 Feb 2025 20:11:41 -0900 (AKST)
From: [email protected]
To: [email protected]
Subject: Test
Hello World!
If you would like forwar emails to a specific server, create a Postfix transport file.
localhost local:
* smtp:[mailcatcher.local]:1025
And mount this file at startup.
$ docker run -d \
-v `pwd`/keys/:/keys/ \
-v `pwd`/logs/:/maillogs/ \
-e SERVERNAME=postfix.example.com \
-v your_transport_file:/etc/postfix/transport \
-p 25:25 \
-p 1025:25 \
netebakari/simple-mail-relay:latest
Content type
Image
Digest
sha256:ec37ce8b6…
Size
56.7 MB
Last updated
over 1 year ago
docker pull netebakari/simple-mail-relay