Skip to content

Commit

Permalink
Port the simple SMTP server to aiosmtpd. It's untested but at least a…
Browse files Browse the repository at this point in the history
…llows some test suites to pass.
  • Loading branch information
jaraco committed Dec 11, 2023
1 parent 43beeb8 commit 235c42e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
24 changes: 12 additions & 12 deletions jaraco/email/smtp.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import smtpd
import asyncore
import asyncio
import argparse

from aiosmtpd.controller import Controller


def _get_args():
p = argparse.ArgumentParser()
p.add_argument('-p', '--port', type=int, help="Bind to port", default=25)
return p.parse_args()


class DebuggingServer(smtpd.DebuggingServer):
def process_message(self, peer, mailfrom, rcpttos, data):
# seriously, why doesn't a debugging server just print everything?
print('peer:', peer)
print('mailfrom:', mailfrom)
print('rcpttos:', rcpttos)
smtpd.DebuggingServer.process_message(self, peer, mailfrom, rcpttos, data)
class DebuggingHandler:
async def handle_DATA(self, server, session, envelope):
print('peer:', session.peer)
print('mailfrom:', envelope.mail_from)
print('rcpttos:', envelope.rcpt_tos)
return '250 OK'


def start_simple_server():
"A simple mail server that sends a simple response"
args = _get_args()
addr = ('', args.port)
DebuggingServer(addr, None)
asyncore.loop()
controller = Controller(DebuggingHandler(), hostname='', port=args.port)
controller.start()
asyncio.new_event_loop().run_forever()
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ install_requires =
jaraco.text>=1.3
jaraco.collections
keyring
aiosmtpd

[options.packages.find]
exclude =
Expand Down

0 comments on commit 235c42e

Please sign in to comment.