root/smtp-dev.py

Revision 934:b628ea903b69, 0.6 kB (checked in by pythy <[email protected]…>, 20 months ago)

Fill tabs by 4 spaces (by code style guide)

Line  
1 from datetime import datetime
2 import asyncore
3 from smtpd import SMTPServer
4
5 class EmlServer(SMTPServer):
6     no = 0
7     def process_message(self, peer, mailfrom, rcpttos, data):
8         filename = '%s-%d.eml' % (datetime.now().strftime('%Y%m%d%H%M%S'), self.no)
9         f = open(filename, 'w')
10         f.write(data)
11         f.close()
12         print '%s saved.' % filename
13         self.no += 1
14
15
16 def run():
17     foo = EmlServer(('localhost', 25), None)
18     try:
19         asyncore.loop()
20     except KeyboardInterrupt:
21         pass
22
23
24 if __name__ == '__main__':
25     run()
Note: See TracBrowser for help on using the browser.