開発環境用smtpサーバとかsmtpプロキシとか。

開発時にメール送信テストした際の参考。

Djangoのmanage.pyコマンドとして開発用smtpサーバを組み込む。

<app_dir>
`-- management/
         |--  commands/
         |        |--  runsmtpdserver.py
         |        |--  runsmtpproxyserver.py
         |        `-- __init__.py
         `-- __init__.py

runsmtpdserver.py

from django.core.management.base import BaseCommand
import asyncore, smtpd

class Command(BaseCommand):
  def handle(self, *args, **opts):
    smtpd.DebuggingServer(('localhost', 25), None)                                                                                                                                                   
    asyncore.loop()


runsmtpproxyserver.py

from django.core.management.base import BaseCommand
import asyncore, smtpd

class Command(BaseCommand):
    def handle(self, *args, **opts):
       server = smtpd.PureProxy(('localhost', 10025), ('リレー先のサーバ', 25))
       asyncore.loop()

pythonって工具箱がついてるイメージだわ。使えば使うほどそう感じる。