FreeBSDでssmtp(Simple SMTP)
長年のexim使いなので,eximのインストールや設定は苦じゃないのですが,マシンの台数が増えるとちょっと面倒ではありました.ましてや,全マシンがSMTPサーバである必要はなく,一台がメールサーバ兼POPサーバで,そこからメールを読み出したいと思っていました.
要は,メールサーバ以外のマシンは,メールに関しては送信専用の場合.例えば,Webサーバだからメールを受信する必要はないけど,cronがdailyやweeklyでメールを各マシンのrootに送るので,それを読みたいような場合.
通常,勝手に立ち上がりやがるsendmailをそのまま使う場合はわりと簡単で,
→sendmailに丸投げ
- 各マシンにメールサーバを入れて,POPサーバにリレーする
→正しいやり方だけど,面倒くさい
そこでssmtp(Simple SMTP).FreeBSDなら,Portsに入っています.
> cat /usr/ports/mail/ssmtp/pkg-descr A secure, effective and simple way of getting mail off a system to your mail hub. It does not include a mail spool to poke around in,and no daemons running in the background. Mail is simply forwarded to the configured mailhost. Extremely easy configuration. WARNING: the above is all it does; it does not receive mail, expand aliases or manage a queue. That belongs on a mail hub with a system administrator. WWW: http://packages.debian.org/stable/mail/ssmtp 適当な訳 セキュアで,便利でシンプルな,メールサーバにメールを転送する方法を提供します. SSMTPは,メールを処理待ちにさせるメールスプールは使いませんし,バックグラウンドで走るデーモンでもありません. ただ単に,きちんと設定されたメールサーバにメールを転送するだけです. SSMTP自体の設定は非常に簡単です. *警告* SSMTPの機能はこれで全てです.メールを受信したり,エイリアスを展開したり,キューを管理したりすることはできません.それらの機能は,きちんと設定されたメールサーバとそのサーバの管理者が行います.
残念ながら活発に開発されているわけではないようですが,非常にシンプルな機能のみが必要なので,これ以上開発することも殆ど無く,問題ないと思います.
Note: This program still works as of 11-14-2009 but note that SSMTP is no longer being developed. You might want to consider an alternative like MSMTP. Note: 22 Feb 2010: SSMTP seems to be maintained. SSMTP 2.6.4-1 was put in the Arch Linux packages at 2009-11-26. And in Debian unstable version 2.6.4-3 was put in their unstable repository on 2010-02-09 and move to testing just 10 days later: http://packages.qa.debian.org/s/ssmtp.html 適当な訳 注:このプログラムは,2009年11月14日現在,稼働はするようですが,SSMTPは既に開発されていないようです.MSMTPのような,代替となるソフトを導入したくなるかと思います. 注:2010年2月22日現在,SSMTPはメンテされているようです.SSMTP 2.6.4.1は2009年11月26日にArch Linuxパッケージに入っています.Debianの非安定版2.6.4-3に入ったあと,2010年2月9日の非安定版レポジトリに入り,10日後にはテスト用に入れられたようです.
最終的に,現時点では安定版とはみなされていないものも,Debianのレポジトリ上ではメンテされているようです.
[2012-07-10] ssmtp 2.64-7 MIGRATED to testing (Britney)
ん?マシンのroot宛のメールを特定のメールサーバに転送したいだけだったら,rootのホームディレクトリに.forwardを書いて飛ばせばいいんじゃないかって?ダメです,.forwardの処理をするのはsendmailなので,sendmailの設定をサボりたい時はその手は使えません.
というわけで,FreeBSD上でPortsでSSMTPを入れてみます.rootになって作業します.
# cd /usr/ports/mail/ssmtp/ # make # make install
インストールすると,以下のような説明文が出ます.
To replace sendmail with ssmtp type "make replace" or change your /etc/mail/mailer.conf to: sendmail /usr/local/sbin/ssmtp send-mail /usr/local/sbin/ssmtp mailq /usr/local/sbin/ssmtp newaliases /usr/local/sbin/ssmtp hoststat /usr/bin/true purgestat /usr/bin/true However, before you can use the program, you should copy the files "revaliases.sample" and "ssmtp.conf.sample" in /usr/local/etc/ssmtp to "revaliases" and "ssmtp.conf" respectively and edit them to suit your needs. ===> Correct pkg-plist sequ
まず,/etc/mail/mailer.confは,指示通りに変更します.
そして,プログラムを使う前に設定ファイルをコピーしろとあるので,その通りにします.
# cp -pv /usr/local/etc/ssmtp/revaliases.sample /usr/local/etc/ssmtp/revaliases /usr/local/etc/ssmtp/revaliases.sample -> /usr/local/etc/ssmtp/revaliases # cp -pv /usr/local/etc/ssmtp/ssmtp.conf.sample /usr/local/etc/ssmtp/ssmtp.conf /usr/local/etc/ssmtp/ssmtp.conf.sample -> /usr/local/etc/ssmtp/ssmtp.conf # emacs -nw /usr/local/etc/ssmtp/revaliases /usr/local/etc/ssmtp/ssmtp.conf
revaliasesの方は,eSMTP aliasesだそうなので,エイリアスを使わない場合は編集の必要はありません.
ssmtp.confは,適当に編集が必要です.
# # /etc/ssmtp.conf -- a 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 # The example will fit if you are in domain.com and your mailhub is so named. #mailhub=mail mailhub=mailserver.example.com # <------- 転送先のメールサーバ(SMTPサーバ)を書く # Example for SMTP port number 2525 # mailhub=mail.your.domain:2525 # Example for SMTP port number 25 (Standard/RFC) # mailhub=mail.your.domain # Example for SSL encrypted connection # mailhub=mail.your.domain:465 # Where will the mail seem to come from? #rewriteDomain= rewriteDomain=www.example.com # <------- 転送元のサーバ名を書く # The full hostname #hostname=_HOSTNAME_ hostname=www.example.com # <------- 転送元のサーバ名を書く # Set this to never rewrite the "From:" line (unless not given) and to # use that address in the "from line" of the envelope. #FromLineOverride=YES # Use SSL/TLS to send secure messages to server. #UseTLS=YES # Use SSL/TLS certificate to authenticate against smtp host. #UseTLSCert=YES # Use this RSA certificate. #TLSCert=/usr/local/etc/ssmtp/ssmtp.pem # Get enhanced (*really* enhanced) debugging information in the logs # If you want to have debugging of the config file parsing, move this option # to the top of the config file and uncomment #Debug=YES
この3箇所くらいです.デーモンじゃないので,設定ファイルを書き換えたあとにデーモンのリロードやリブートも必要ありません.
あと,メールサーバ側で,www.example.comからのメールを受け付けるようにして下さい.
うちの場合はeximなので,www.example.com自体をローカルドメンとしてメールサーバで取り込むようにしました.
domainlist local_domains = @:*.example.org
これでsendmailは止めても大丈夫です.
軽くて良い感じです.