HAYAGUI

FreeBSD 4.8 + smtpclient

はじめに

コマンドラインからメールする時は、普通 mail コマンドを利用しますが、 mail コマンドは、ローカルのsendmailなどのMTA(Mail Transfer Agent)に配送を依頼します。 しかし、Windowsでメールする時は、smtpサーバを設定しています。

コマンドラインからsmtpサーバを指定できるのが、smtpclient です。

インストール

smtpclient は、ここ(http://www.engelschall.com/sw/smtpclient/)からゲットします。

上のサイトが閉鎖されたので、FreeBSDのPorts一覧からゲット。 2005/10/07

解凍。

> tar zxvf smtpclient-1.0.0.tar.gz
> cd smtpclient-1.0.0
> ls
ChangeLog               config.h.in             smtpclient_errno.h
LICENSE                 configure               smtpclient_getopt.c
Makefile.in             configure.in            smtpclient_getopt.h
PORTING                 etc                     smtpclient_main.c
README                  smtpclient.1            smtpclient_vers.c
VERSIONS                smtpclient.pod          smtpclient_vers.h
acconfig.h              smtpclient_errno.c
./configure , make した後、root になって、make install します。
> ./configure

> make

> su -
Password:
mico# cd /home/kenz/smtpclient-1.0.0
mico#
mico# make install

使ってみよう

まずヘルプ。-S オプションで smtpサーバを設定できるんですね。
mico# /usr/local/bin/smtpclient -h
Usage: smtp [options] recipients ...

Message Header Options:
  -s, --subject=STR      subject line of message
  -f, --from=ADDR        address of the sender
  -r, --reply-to=ADDR    address of the sender for replies
  -e, --errors-to=ADDR   address to send delivery errors to
  -c, --carbon-copy=ADDR address to send copy of message to

Processing Options:
  -S, --smtp-host=HOST   host where MTA can be contacted via SMTP
  -P, --smtp-port=NUM    port where MTA can be contacted via SMTP
  -M, --mime-encode      use MIME-style translation to quoted-printable
  -L, --use-syslog       log errors to syslog facility instead of stderr

Giving Feedback:
  -v, --verbose          enable verbose logging messages
  -V, --version          display version string
  -h, --help             display this page
最初は、ローカルのMTAを利用する mail コマンドでメールしてみます。
mico# echo "hoge" | mail -s test kenz@eden.hayagui.com
次に、MTAのsendmail を止めて mail が届かないことを確認します。
mico# ps -ax | grep sendmail
   84  ??  Ss     0:00.03 sendmail: accepting connections (sendmail)
   87  ??  Is     0:00.00 sendmail: Queue runner@00:30:00 for /var/spool/client
mico# kill -9 84
mico# kill -9 87
mico# ps -ax | grep sendmail
mico#
mico# echo "hoge" | mail -s test kenz@eden.hayagui.com
届かない。

次に、smtpclient でメールしてみます。

mico# echo "hoge" | /usr/local/bin/smtpclient -s test -S 192.168.0.8 kenz@eden.hayagui.com
届きます。 では、-v オプションをつけてやり取りを見てみましょう。
mico# echo "hoge" | /usr/local/bin/smtpclient -s test -S 192.168.0.8 -v  kenz@eden.hayagui.com
192.168.0.8 --> 220 eden.hayagui.com ESMTP Sendmail 8.11.6/8.11.6; Fri, 12 Sep 2003 23:01:05 +0900 (JST)
192.168.0.8 <-- HELO mico.hayagui.com
192.168.0.8 --> 250 eden.hayagui.com Hello mico.hayagui.com [192.168.0.7], pleased to meet you
192.168.0.8 <-- MAIL FROM: <root@mico.hayagui.com>
192.168.0.8 --> 250 2.1.0 <root@mico.hayagui.com>... Sender ok
192.168.0.8 <-- RCPT TO: <kenz@eden.hayagui.com>
192.168.0.8 --> 250 2.1.5 <kenz@eden.hayagui.com>... Recipient ok
192.168.0.8 <-- DATA
192.168.0.8 --> 354 Enter mail, end with "." on a line by itself
192.168.0.8 <-- .
192.168.0.8 --> 250 2.0.0 h8CE15n00207 Message accepted for delivery
192.168.0.8 <-- QUIT
192.168.0.8 --> 221 2.0.0 eden.hayagui.com closing connection
これはいい。

戻る



(C)1999 - 2003 Kenji Ito All rights reserved.