telnetでSMTPをしゃべる

telnetでSMTPサーバに接続してテストメールを送るテンプレ
SMTPサーバを作ったときに、何も入っていない環境でテストをする時に役に立つ。
"HELO"はもう古いか。"EHLO"の方が今風かも。

# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 example.jp ESMTP Postfix

helo example.jp
250 example.jp

mail from:sender@example.jp
250 2.1.0 Ok

rcpt to:user@example.com
250 2.1.5 Ok

data
354 End data with <CR><LF>.<CR><LF>

subject:test mail
test
desu
です
hoge
.
250 2.0.0 Ok: queued as 0D46A66975

quit
221 2.0.0 Bye
Connection closed by foreign host.

# ↑は、見やすい様に、わざと入力手前に改行を入れています。

追記1

id:ttomoさんより、ヘッダ部とボディ部の間には空行(CRLF)を入れるべき、と教えていただきました!(↑の例だと、Subjectの下あたり)

The body is simply a sequence of characters that follows the header and is separated from the header by an empty line (i.e., a line with nothing preceding the CRLF).

RFC 2822 Internet Message Format

追記2

id:tsekineさんより、コメントにて以下指摘をいただきました。ありがとうございます!

HELO (SMTP) で挨拶したら 7 bit オンリー。SMTP コマンドは大文字。Path (sender address, recipient address) は <> で囲う。Subject: の後に空白がない。ついでに言うと、自分でサーバ立てたなら submission ポートも確認した方がいい。

参考


電子メールプロトコル―基本・実装・運用

電子メールプロトコル―基本・実装・運用

  • 作者: デイビッドウッド,David Wood,佐々木雅之,千葉猛,日比野洋克,渡部直明,沢野弘幸,鄭隆幸,平塚伸世,大川佳織
  • 出版社/メーカー: オライリー・ジャパン
  • 発売日: 2000/11
  • メディア: 単行本
  • 購入: 2人 クリック: 24回
  • この商品を含むブログ (8件) を見る