Skip to content

Instantly share code, notes, and snippets.

@lrivallain
Last active August 18, 2017 07:13
Show Gist options
  • Select an option

  • Save lrivallain/592db5524dd6ce3f5d4bcb2d582ce029 to your computer and use it in GitHub Desktop.

Select an option

Save lrivallain/592db5524dd6ce3f5d4bcb2d582ce029 to your computer and use it in GitHub Desktop.
Fake SMTP server

Run it

chmod +x fakeSMTPserver.py
sudo ./fakeSMTPserver.py

Change behavior

Print messages out to stdout

sudo python -m smtpd -n -c DebuggingServer

Bind IP address or port

sudo python -m smtpd -n 127.0.0.1:25

Both messages to stdout and IP address bind

sudo python -m smtpd -n -c DebuggingServer 10.10.10.254:25
#!/usr/bin/env python
"""A noddy fake smtp server."""
import smtpd
import asyncore
class FakeSMTPServer(smtpd.SMTPServer):
"""A Fake smtp server"""
def __init__(*args, **kwargs):
print "Running fake smtp server on port 25"
smtpd.SMTPServer.__init__(*args, **kwargs)
def process_message(*args, **kwargs):
pass
if __name__ == "__main__":
smtp_server = FakeSMTPServer(('localhost', 25), None)
try:
asyncore.loop()
except KeyboardInterrupt:
smtp_server.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment