Cygwinでsendmailコマンドからメール送信を出来るようにする方法
最近、Cygwin上でPerlスクリプトを作成しているが、スクリプトからメールを
飛ばす必要が出たため、ローカルPC上からsendmailコマンドを使用するためのメモ。
なお、受信のための設定は不要なので今回はしない。
前提として、sendmailコマンドにはsendmail、または、sendmailコマンド互換のMTAが必要。
そして、CygwinにはCygwinのインストーラから簡単にインストールできるsendmail互換のMTA、
exim(いくしむ)があるので、これをインストールして使用する。
eximの設定
- /usr/bin/exim-configを実行する。
$ /usr/bin/exim-config ************************************************ This script sets some key parameters of the exim installation and starts the exim daemon. See the details in /usr/share/doc/Cygwin/exim-X-Y.README. Interrupt with ^D. OK. No usernames contain spaces. OK. The /etc/aliases file contains "postmaster". OK. /etc/exim.conf created from /etc/defaults/etc/exim.conf. Looking for the fully qualified primary hostname. Is it "localpc.xx.co.jp"? (yes/no) no Enter your fully qualified hostname. mail.xxxxxxxx.com
接続するメールサーバを聞かれるので、ローカルPCのメーラで使っているPOPメールサーバのFQDNを入力。
OK. The hostname mail.xxxxxxxx.com was saved in /etc/exim.conf. OK. The mode and ownership of the /etc/exim.conf file are now: -rw-rw-r-- 1 18 0 35839 Dec 1 19:10 /etc/exim.conf INFO: Some programs expect /usr/sbin/sendmail to handle mail. Currently it is a symbolic link to /usr/bin/exim. Do you want to link /usr/sbin/sendmail to /usr/bin/exim ? (yes/no) yes OK. Done.
/usr/sbin/sendmailコマンドのリンクを作るか聞かれるので、 yes
Do you want to install the exim daemon as a service? (yes/no) no Do you want to start the exim daemon as a job now? (yes/no) no
デーモンサービスにするか?いまデーモンを立ち上げるか聞かれるが、
送信するだけならデーモンは使わないので両方 no
OK. Type "/usr/bin/exim -bd -q15m" to start the exim daemon job. INFO: The exim log files are in /var/log/exim. When everything else fails, read /usr/share/doc/Cygwin/exim-X-Y.README, or look up the documentation on www.exim.org. Many happy mailings :)
もしあとからデーモンを起動するなら、
$ /usr/bin/exim -bd -q15m
デーモンを停止するなら
$ pkill exim
テスト送信
$ /usr/sbin/sendmail -f self@xxxx.com self@xxxx.com Subject:test test .
デーモン起動は不要。
上のように、sendmailコマンドを入力し、Subject:testと、本文のtest、終了の意味の.を入力してEnter。
自分に届けばOK。