Posted By


inky76 on 03/07/12

Statistics


Viewed 879 times
Favorited by 0 user(s)

SMTP sink server


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  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'),
  9. self.no)
  10. f = open(filename, 'w')
  11. f.write(data)
  12. f.close
  13. print '%s saved.' % filename
  14. self.no += 1
  15.  
  16.  
  17. def run():
  18. foo = EmlServer(('localhost', 25), None)
  19. try:
  20. asyncore.loop()
  21. except KeyboardInterrupt:
  22. pass
  23.  
  24.  
  25. if __name__ == '__main__':
  26. run()

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.