Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

DKIM対応のメール中継サーバー

License

NotificationsYou must be signed in to change notification settings

netebakari/simple-mail-relay

Repository files navigation

README in Japanese ishere

What is this?

A simple mail relay server built with Postfix and OpenDKIM. When you send mail to this container, it forwards the mail externally with a DKIM signature, depending on the sender domain. Supports multiple domains. The DKIM selector is fixed todefault.

Motivation

  • I want a simple mail relay server and know how DKIM works.
  • I want to keep logs of when, to whom, and what kind of emails were sent, as long as storage capacity allows.
  • I want to output Postfix logs to standard output for easy handling.

Docker Hub

https://hub.docker.com/r/netebakari/simple-mail-relay

Environment Tested

Ubuntu 22.04 LTS + Docker 27.5.1

Logs

Postfix log

Since logs are output to standard output, you can check them withdocker logs ordocker compose logs.

Mail logs

Two types of log files are output:

  • CSV file summarizing the mail's timestamp, subject, and recipient in one line.
  • Plain text file containing all information, including the mail header, body, attachment of single mail.

How to Start

1. Create Mail Log Directories

$ 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

Mail logs are stored by themaillog user, whose user / group id is 1000:1000.

2. DKIM Configuration

Create DKIM keys

$ mkdir keys

Create DKIM public/private keys using theopendkim-genkey command and put them into thekeys/ directory. You can store keys for multiple domains.

The filename should be in the formatFQDN + .private, such asexample.com.private.

Register keys in your DNS

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...."

3. Start

Initially, all emails are forwarded tomailcatcher. Don't worry, no mails will be sent externally!

docker compose up -d

4. Send Test Email

Send a mail

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 1025HELO localhostMAIL FROM: test@example.comRCPT TO: someone@netebakari.localDATAFrom: test@example.comTo: someone@netebakari.localSubject: TestHello World!.QUIT

Check the mail logs

Check the email body by mailcatcher (working athttp://localhost:1080) or log file in/logs/raw/YYYY-MM-DD/. It would be just like:

From test@example.com  Mon Feb 17 13:20:08 2025Return-Path: <test@example.com>X-Original-To: logging@localhostDelivered-To: logging@localhostReceived: from localhost (unknown [172.18.0.1])by postfix.netebakari.local (Postfix) with SMTP id 99D3D53C16for <someone@netebakari.local>; Mon, 17 Feb 2025 13:19:57 +0000 (UTC)DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=example.com;s=default; t=1739798408;bh=z85OKVJZHnmg3qFlSpLbpPCZ00irfBdrzQUtabiSl3A=; h=From:To:Subject;b=IIbFlx1MTKZcR7/OQiw7qVpfNEsh05BSrgZ7GIwXYGxXg/wpWUXb2JWyxbF31k7pB FDIAAi2tgj+/ULHSvPX44Phjnqc5yRetrWRJUUndD4bC9kYhZu4TpSwBjp3Mz4htgY 5Rnmg0YwXqcEqU8PKpJqSo0k+JTbZ6xbuOEg73YLHdjq3XAneFWBUV8VubcRjp/owk yzR/Ke2eoturx7ajGvt+qMBFZvuFasg8OHjSGPp+pOscH5ZLH5SfG3DQycwBigswxC nKot1SLEEYlWIQVRyiLBSADYRwqnrM2WvD46m7eXuOIPJlH/mfEV25/9QC1yM+73lt K3binxrS+YCzA==From: test@example.comTo: someone@netebakari.localSubject: TestHello World!

5. Postfix Configuration

Change server name

Change theSERVERNAME environment variable incompose.yaml to the server's FQDN. It is highly recommended that this FQDN be reverse resolvable.

Customizetransport file

If you want this mail relay server to deliver maildirectly to the internet, comment out the/etc/postfix/transport mount incompose.yaml. Atransport file with the following content will be automatically generated and used:

localhost   local:*           smtp:

If you would like forward mails to a specific server, create a Postfixtransport⁠ file and mount it to/etc/postfix/transport. Thepostmap command is executed at start up time.

localhost   local:*           smtp:[email-smtp.ap-northeast-1.amazonaws.com]:25

Remove mailcatcher

Remove mailcathcer incompose.yaml if you don't need it.


[8]ページ先頭

©2009-2025 Movatter.jp