Exim4の設定を何度か行ったが、たまにしか設定しないので毎度とまどってしまう。そこでlogファイルに反映される成功例と失敗例を記録しておく
Exim4のInstall
次のコマンドでLinux BoxへInstallするのだがarchiveの取得が失敗する場合にはsudo apt-get updateを実行する
$sudo apt install exim4 mailutils
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
$sudo apt-get update
Install後に設定スクリプトを動かす
$ sudo dpkg-reconfigure exim4-config
- インターネット経由(internet site): 直接他のサーバーへメールを送信・受信します。固定IPアドレスとドメインがある場合に適しています。
- スマートホスト経由(mail sent by smarthost; received via SMTP or fetchmail): プロバイダのSMTPサーバーやGmailなどの外部リレーサーバー(スマートホスト)を経由してメールを送信します。サーバーから通知メールを送りたいだけの場合はこれを選びます。
- ローカル配信のみ(local delivery only): サーバー内部(rootや各ユーザー宛て)のメールのみを処理し、外部には送信しません。
smtp serverとの接続
2つのファイルの編集が必要。ファイルに記述する内容はメールアカウントとアプリパスワード(gmailの場合)である。アプリパスワードはGoogle Accountに2段階認証を設定すれば取得できる。
アプリ パスワードでログインする - Google アカウント ヘルプ
Debian リファレンス
$ sudo vi /etc/exim4/passwd.client
sudo echo "*:foobar@gmail.com:nksgmzdfryvpfeuh" >> /etc/exim4/passwd.client
$ sudo vi /etc/exim4/update-exim4.conf.conf
sudo echo "dc_smarthost='smtp.gmail.com::587'" >> /etc/exim4/update-exim4.conf.conf
送信スクリプト
echo "hello" | mail -r pi@sy -s "test" foobar@gmail.com # -rは無くてもOK
Ruby
IO.popen(["mail", "-r", "pi@sy", "-s", "test", "foobar@gmail.com"], "w") do |io|
io.puts "hello"
end
または
#!/usr/bin/env ruby
system('echo "hello" | mail -s "test" foobar@gmail.com')
Trouble Shooting
/var/log/exim4/mainlogにログが記録される。成功時には直ぐにe-mailが届く。
成功例
2026-06-26 16:52:56 Warning: No server certificate defined; will use a selfsigned one.
Suggested action: either install a certificate or change tls_advertise_hosts option
2026-06-26 16:52:56 exim 4.96 daemon started: pid=1078758, -q30m, listening for SMTP on [127.0.0.1]:25 [::1]:25
2026-06-26 16:52:58 Start queue run: pid=1078759
2026-06-26 16:52:58 End queue run: pid=1078759
2026-06-26 16:53:29 1wd1NR-004Wdq-2G <= pi@sy U=pi P=local S=346
2026-06-26 16:53:31 1wd1NR-004Wdq-2G H=smtp.gmail.com [2404:6800:400b:c015::6c] TLS error on connection (recv): The TLS connection was non-properly terminated.
2026-06-26 16:53:31 1wd1NR-004Wdq-2G => foobar@gmail.com R=smarthost T=remote_smtp_smarthost H=smtp.gmail.com [2404:6800:400b:c015::6c] TFO X=TLS1.3:ECDHE_X25519__ECDSA_SECP256R1_SHA256__AES_256_GCM:256 CV=yes DN="CN=smtp.gmail.com" A=plain K C="250 2.0.0 OK 98e67ed59e1d1-37df400ba0bsm3473039a91.15 - gsmtp"
2026-06-26 16:53:31 1wd1NR-004Wdq-2G Completed
失敗例
2026-06-26 16:48:02 Warning: No server certificate defined; will use a selfsigned one.
Suggested action: either install a certificate or change tls_advertise_hosts option
2026-06-26 16:48:02 exim 4.96 daemon started: pid=1078290, -q30m, listening for SMTP on [127.0.0.1]:25 [::1]:25
2026-06-26 16:48:04 Start queue run: pid=1078291
2026-06-26 16:48:04 End queue run: pid=1078291
2026-06-26 16:48:38 1wd1Ik-004WWJ-2r <= pi@sy U=pi P=local S=344
2026-06-26 16:48:39 1wd1Ik-004WWJ-2r plain authenticator failed H=smtp.gmail.com [2404:6800:400b:c017::6d] 535-5.7.8 Username and Password not accepted. For more information, go to
535 5.7.8 https://support.google.com/mail/?p=BadCredentials d2e1a72fcca58-845c93a53d2sm693601b3a.33 - gsmtp
2026-06-26 16:48:40 1wd1Ik-004WWJ-2r login authenticator failed H=smtp.gmail.com [2404:6800:400b:c017::6d] 535-5.7.8 Username and Password not accepted. For more information, go to
535 5.7.8 https://support.google.com/mail/?p=BadCredentials d2e1a72fcca58-845c93a53d2sm693601b3a.33 - gsmtp
2026-06-26 16:48:40 1wd1Ik-004WWJ-2r H=smtp.gmail.com [2404:6800:400b:c017::6d] TLS error on connection (recv): The TLS connection was non-properly terminated.
2026-06-26 16:48:40 1wd1Ik-004WWJ-2r ** foobar@gmail.com R=smarthost T=remote_smtp_smarthost H=smtp.gmail.com [2404:6800:400b:c017::6d] X=TLS1.3:ECDHE_X25519__ECDSA_SECP256R1_SHA256__AES_256_GCM:256 CV=yes DN="CN=smtp.gmail.com": SMTP error from remote mail server after pipelined end of data: 530-5.7.0 Authentication Required. For more information, go to\n530 5.7.0 https://support.google.com/accounts/troubleshooter/2402620. d2e1a72fcca58-845c93a53d2sm693601b3a.33 - gsmtp
2026-06-26 16:48:40 1wd1Im-004WWP-0Z <= <> R=1wd1Ik-004WWJ-2r U=Debian-exim P=local S=2021
2026-06-26 16:48:40 1wd1Ik-004WWJ-2r Completed
2026-06-26 16:48:40 1wd1Im-004WWP-0Z => pi <pi@sy> R=local_user T=mail_spool
2026-06-26 16:48:40 1wd1Im-004WWP-0Z Completed
/var/log/exim4/mainlog (END)
smtp serverにeonet webメールを使った場合smtp serverからはConnection timed outの応答が来た。
2026-06-26 18:17:08 1wd2gO-004XRy-1U <= pi@sy U=pi P=local S=326
2026-06-26 18:18:41 1wd2d3-004XPj-2v H=kopt-eonet-smtps.xspmail.jp [2001:240:bb81:94:202:238:198:34]: SMTP timeout after initial connection: Connection timed out
2026-06-26 18:22:08 1wd2gO-004XRy-1U H=kopt-eonet-smtps.xspmail.jp [2001:240:bb81:94:202:238:198:34]: SMTP timeout after initial connection: Connection timed out
2026-06-26 18:23:42 1wd2d3-004XPj-2v H=kopt-eonet-smtps.xspmail.jp [202.238.198.34]: SMTP timeout after initial connection: Connection timed out
2026-06-26 18:23:42 1wd2d3-004XPj-2v == foobar@gmail.com R=smarthost T=remote_smtp_smarthost defer (110): Connection timed out H=kopt-eonet-smtps.xspmail.jp [202.238.198.34]: SMTP timeout after initial connection
2026-06-26 18:27:08 1wd2gO-004XRy-1U H=kopt-eonet-smtps.xspmail.jp [202.238.198.34]: Remote host closed connection in response to initial connection
2026-06-26 18:27:08 1wd2gO-004XRy-1U == foobar@gmail.com R=smarthost T=remote_smtp_smarthost defer (-18) H=kopt-eonet-smtps.xspmail.jp [202.238.198.34]: Remote host closed connection in response to initial connection
