エセSMTPサーバー

メールを自動送信するシステムのテストをしたいとか、ドメイン設定やSSL設定に必要な認証メールを受け取りたいとか、ありますよね。

こんなとき「届いたメッセージのアカウント確認もメッセージ転送も行わず、ひたすらOKステータスを返してメッセージの内容を出力する」というエセSMTPサーバーが欲しくなります。

Pythonに便利なワンライナーが用意されていました。

$ sudo python -m smtpd -n -c DebuggingServer 0.0.0.0:25

たったこれだけでエセSMTPサーバーが起動します。
オプションの詳細はこちら。

Usage: smtpd.py [options] [localhost:localport [remotehost:remoteport]]

Options:

    --nosetuid
    -n
        This program generally tries to setuid `nobody', unless this flag is
        set.  The setuid call will fail if this program is not run as root (in
        which case, use this flag).

    --version
    -V
        Print the version number and exit.

    --class classname
    -c classname
        Use `classname' as the concrete SMTP proxy class.  Uses `PureProxy' by
        default.

    --debug
    -d
        Turn on debugging prints.

    --help
    -h
        Print this message and exit.

Version: Python SMTP proxy version 0.2

If localhost is not given then `localhost' is used, and if localport is not
given then 8025 is used.  If remotehost is not given then `localhost' is used,
and if remoteport is not given, then 25 is used.

-c classname オプションは DebuggingServer だけでなく、以下のクラス名を指定して簡易的なSMTPサービスを提供することもできます。

  • SMTPServer
  • DebuggingServer
  • PureProxy
  • MailmanProxy
  • Python Documentation: 20.13. smtpd — SMTP サーバー
    Source Code: cpython/file/2.7/Lib/smtpd.py

    コメントを残す

    メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

    *