1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | from datetime import datetime
import asyncore
from smtpd import SMTPServer
class EmlServer(SMTPServer):
no = 0
def process_message(self, peer, mailfrom, rcpttos, data):
filename = '%s-%d.eml' % (datetime.now().strftime('%Y%m%d%H%M%S'),
self.no)
f = open(filename, 'w')
f.write(data)
f.close
print '%s saved.' % filename
self.no += 1
def run():
foo = EmlServer(('localhost', 25), None)
try:
asyncore.loop()
except KeyboardInterrupt:
pass
if __name__ == '__main__':
run()
|
More like this
- SMTP sink server: prettier output by huwshimi 3 years ago
- Email queue in DB by fish2000 3 years, 1 month ago
- Testing Email Registration by osborn.steven 4 years, 2 months ago
- run "silent" dev server by justinlilly 5 years, 11 months ago
- Better debugging mail server by yourcelf 2 years, 3 months ago
Comments
I'm using this to test ubernostrum's great django-registration package from http://code.google.com/p/django-registration/ and it's been quite helpful while I'm tweaking the registration messages and confirmations. Thanks!
#
I'm so happy to learn that it's helpful to you:)
Note: This sinppet has been fixed for bug overwriting files when received multi-messages in on session.
#
This snippet requires running it from root account. You have to add some code to bind to a port number over 1024. Like in line 17 and 18:
and later in line 26 and later:
Of course, you have to import sys at the top of the module too.
#
I found another one: SMTP Mailsink
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440690
#
very useful, thanks for sharing this snippet
#
Line 12 should be: f.close()
#
instead of writing an .eml you can directly send your mail to the built in python mail server. on a shell do:
then send your mails to localhost:25 and you will see the results immediately :-)
#
thank you man, this is awesome!! helps so much!
#
I've added a version with nicer, more verbose terminal messages: http://www.djangosnippets.org/snippets/2010/
#
I'm still using this after years.
#
Me too!
#
I'm so happy to learn that it's helpful it's been quite helpful while I'm tweaking the registration messages and confirmations. Thanks! RP ---iPad 3 Cases---
#
very useful, thanks for sharing this snippet, save each session into an EML file. *.eml could be viewed with your favorite email client, you need not send them out. Thanks! RP ---Samsung Galaxy S3 cases---
#