かつてはsSMTPがデフォルトMTAだったGentooだが、そういえばNullmailerになっていたことを思い出してcronの通知にこれを使うことにした。
ついでに、二段階認証を適用したGoogleアカウントでsmtp.gmail.comを使う方法も兼ねる。
アプリパスワード
Googleのサービスには、二段階認証などを行っているときでも特定の行動でパスワード認証を許可する時に用いる16桁のパスワードを発行できる。
環境によってはsmtp.gmail.com宛にSMTPでメールを送るにはこれを使うしか無いため、あらかじめ生成しておくこと。
Nullmailer設定
なにもしていない場合は設定ファイル不足なので emerge --config
を実行。
(と言っても未設定だと空ファイルが2つ出来るだけだが)
# emerge --config nullmailer
Configuring pkg...
* Setting /etc/nullmailer/me
hostname: Unknown host
* Setting /etc/nullmailer/defaultdomain
hostname: Unknown host
/etc/nullmailer/me
と /etc/nullmailer/defaultdomain
を修正。
ここではホスト名を "seriko" 、ドメイン名を "runningon.ssp" と仮定する。
seriko
runningon.ssp
そして一番肝心なリレー先を設定する /etc/nullmailer/remotes
を修正。
man nullmailer-send
を読めば判るが、かつてはオプションを指定するのにハイフン2つが必要だった(--port=587
等)が、現在は不要になっているので注意。
# man nullmailer-send
nullmailer-send(8) System Manager's Manual nullmailer-send(8)
NAME
nullmailer-send - Send queued messages
SYNOPSIS
nullmailer-send
DESCRIPTION
-- <snip> --
CONTROL FILES
All the control files are reread each time the queue is run.
helohost
Sets the environment variable $HELOHOST which is used by the SMTP protocol module to set the parameter given to the HELO command.
Defaults to the value of the me configuration file.
-- <snip> --
remotes
This file contains a list of remote servers to which to send each message. Each line of this file contains a remote host name or
address followed by an optional protocol string, separated by white space. The protocol name defaults to smtp, and may be followed
by additional options for that module. See the "PROTOCOL OPTIONS" section for a list of the available options. The options may
optionally be prefixed by -- but this is not required. The line is parsed according to standard shell quoting rules. For example,
to connect to port 2525 on your SMTP smart host, which also requires SMTP authentication, and initiate TLS with STARTTLS, use:
smarthost.dom smtp port=2525 starttls user=user pass='my pass phrase'
Blank lines and lines starting with a pound (#) are ignored.
-- <snip> --
ということで転送先を一行追加する。
ここでは seriko.runningon.ssp@gmail.com / xxxxxxxxxxxxxxxx というアカウントとアプリパスワードを仮定している。
smtp.gmail.com smtp port=587 user=seriko.runningon.ssp@gmail.com pass=xxxxxxxxxxxxxxxx starttls
これで nullmailer をdefaultランタイムに追加して、起動 or 再起動。
# rc-update add nullmailer default
* service nullmailer added to runlevel default
# /etc/init.d/nullmailer start
* Starting nullmailer ...
疎通確認
疎通確認だが、Gentooでは何もしないとmailxが入ってないので導入。
# emerge -vp mailx
These are the packages that would be merged, in order:
Calculating dependencies... done!
[ebuild N ] mail-client/mailx-support-20060102-r2::gentoo 9 KiB
[ebuild N ] net-libs/liblockfile-1.09::gentoo 32 KiB
[ebuild N ] mail-client/mailx-8.1.2.20050715-r6::gentoo 129 KiB
Total: 3 packages (3 new), Size of downloads: 169 KiB
# emerge mailx
それではテスト。
# echo "This mail is test mail." | mailx -s "test mail" maruchii.inside@gmail.com
# tail /var/log/nullmailer/nullmailer.log
Trigger pulled.
Rescanning queue.
Starting delivery, 1 message(s) in queue.
Starting delivery: host: smtp.gmail.com protocol: smtp file: 0000000000.0000
From: <root@seriko.runningon.ssp> to: <maruchii.inside@gmail.com>
Message-Id: <0000000000.000000.0000.nullmailer@seriko>
smtp: Succeeded: 250 2.0.0 OK 0000000000 xxxxxxxxxxxxxxxx.xx - gsmtp
Sent file.
Delivery complete, 0 message(s) remain.
これで送信できているはず。
ちなみに...
やりたかったこと。
# eix-sync && emerge -uDNqp @world |& mailx -e -s "Ebuild updates" seriko.runningon.ssp@gmail.com
追記(2018/03/01)
少し修正。eixを入れない環境のため。
# emerge --sync -q 2&>1 | logger -t emerge-sync -p cron.info && emerge -uDNqp @world |& mailx -e -s "Ebuild updates" seriko.runningon.ssp@gmail.com