Appearance
ローカル用Postfixを構築
ローカルで動かせるPostfixサーバを立てます。
cf. https://www.postfix.org/STANDARD_CONFIGURATION_README.html
構築手順
インストール
- Postfixをインストールします。
shell
sudo apt update
sudo apt install postfix画面に表示された
Postfix Configurationの選択肢でLocal onlyを選択します。バージョンを表示し、インストールが成功していることを確認します。
shell
# バージョン確認
postconf | grep mail_version- Dovecotをインストールします。
shell
sudo apt install dovecot-core dovecot-pop3d dovecot-imapd- メールディレクトリを作成します。
shell
maildirmake.dovecot ~/Maildir設定ファイル作成
/etc/postfix/main.cf
ini
home_mailbox = Maildir//etc/dovecot/dovecot.conf
ini
protocols = imap pop3ini
listen = */etc/dovecot/conf.d/10-mail.conf
ini
mail_driver = maildir
mail_home = /home/%{user | username}
mail_path = ~/Maildir/etc/dovecot/conf.d/10-auth.conf
ini
auth_mechanisms = plain login/etc/dovecot/conf.d/10-ssl.conf
ini
ssl = no設定ファイル適用
- Postfixを再起動します。
shell
sudo systemctl restart postfix- dovecotを再起動します。
shell
sudo systemctl restart dovecotメール送信テスト
- テスト用ユーザを作成します。
shell
sudo adduser test-user- ディレクトリの書き込み権限を変更します。
shell
sudo chmod 777 /var/spool/mail- 自分自身にメールを送信します。下記はコマンド例およびその出力です。
shell
telnet localhost 25nob@nob-postfix:~$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 nob-postfix ESMTP Postfix (Ubuntu)shell
helo localhosthelo localhost
250 nob-postfixshell
mail from: test-user@nob-postfixmail from: test-user@nob-postfix
250 2.1.0 Okshell
rcpt to: test-user@nob-postfixrcpt to: test-user@nob-postfix
250 2.1.5 Okshell
datadata
354 End data with <CR><LF>.<CR><LF>shell
Subject: Postfix Test
Hello Postfix!
.Subject: Postfix Test
Hello Postfix!
.
250 2.0.0 Ok: queued as 2B02BC47D5shell
quitquit
221 2.0.0 Bye
Connection closed by foreign host.メール受信テスト
- 受信確認のコマンド例およびその出力です。
shell
telnet localhost 143nob@nob-postfix:~$ telnet localhost 143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 LOGIN-REFERRALS ID ENABLE IDLE SASL-IR LITERAL+ AUTH=PLAIN AUTH=LOGIN] Dovecot ready.shell
1 login test-user p@ssw0rd1 login test-user p@ssw0rd
1 OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE REPLACE SNIPPET=FUZZY PREVIEW=FUZZY PREVIEW SPECIAL-USE STATUS=SIZE SAVEDATE COMPRESS=DEFLATE INPROGRESS NOTIFY LITERAL+] Logged inshell
2 list "" *2 list "" *
* LIST (\HasNoChildren) "." INBOX
2 OK List completed (0.007 + 0.000 + 0.006 secs).shell
3 select INBOX3 select INBOX
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.
* 1 EXISTS
* 1 RECENT
* OK [UNSEEN 1] First unseen.
* OK [UIDVALIDITY 1785640003] UIDs valid
* OK [UIDNEXT 2] Predicted next UID
3 OK [READ-WRITE] Select completed (0.004 + 0.000 + 0.003 secs).shell
4 fetch 1 body[]4 fetch 1 body[]
* 1 FETCH (FLAGS (\Seen \Recent) BODY[] {450}
Return-Path: <test-user@nob-postfix>
X-Original-To: test-user@nob-postfix
Delivered-To: test-user@nob-postfix
Received: from localhost (localhost [IPv6:::1])
by nob-postfix (Postfix) with SMTP id 2B02BC47D5
for <test-user@nob-postfix>; Sun, 02 Aug 2026 03:04:27 +0000 (UTC)
Subject: Postfix Test
Message-Id: <20260802030452.2B02BC47D5@nob-postfix>
Date: Sun, 02 Aug 2026 03:04:27 +0000 (UTC)
From: test-user@nob-postfix
Hello Postfix!
)
4 OK Fetch completed (0.001 + 0.000 secs).shell
5 logout5 logout
* BYE Logging out
5 OK Logout completed (0.001 + 0.000 secs).
Connection closed by foreign host.