Ubuntu 12.04 でメールサーバを立てずに sSMTP で CRON メールを送信するには

June 2, 2013

CRON などでメールを送信する際に、ざっくりと Postfix などを入れてしまっていた。
しかし、そもそも既にメールサーバが立っていれば、そこを経由して送信すれば MTA デーモンを動かす必要はない。

MSPに何を使うか探したところ、sSMTP が一番良さそうなのでこれを使うことに。
Ubuntu 12.04 で CRON の MAILTO でメール送信をするまでの設定のメモ。

インストール
1
2
$ sudo apt-get install mailutils  
$ sudo apt-get install ssmtp
設定

/etc/ssmtp/ssmtp.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=postmaster

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=<送信に使う SMTP サーバ>

# Where will the mail seem to come from?
rewriteDomain=<上書きするドメイン>

# The full hostname
hostname=<このホストの FQDN>

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=NO

mailhub はその名のとおり経由するメールサーバを指定する。
rewriteDomain は経由先のメールサーバのドメインを指定する。設定しないとドメインが不正と判断され、迷惑メール扱いになる可能性が高い。

FromLineOverride もわかりづらいが YES にすると本来の From が効く。よって、外からみるとドメインが不正と判断されるだろう。

CRON 設定
1
MAILTO=<送信先メールアドレス>

送信先を書いておく。

sSMTP

tilfin freelance software engineer