- March 9, 2007
- Pre .96
- email debug smtp server eml
- 41 (after 41 ratings)
In development, we need a SMTP Server to see the results of send mail via SMTP protocol in Python application. Instead of configure a mail daemon, we could use this little script to receive the SMTP request, and save each session into an EML file. *.eml could be viewed with your favorite email client, you need not send them out.
Update: Fix bug for overwrite files when received multi-message in one SMTP session.
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
- Serialize a model instance by chriswedgwood 1 week, 6 days ago
- Automatically setup raw_id_fields ForeignKey & OneToOneField by agusmakmun 9 months, 2 weeks ago
- Crispy Form by sourabhsinha396 10 months, 1 week ago
- ReadOnlySelect by mkoistinen 10 months, 3 weeks ago
- Verify events sent to your webhook endpoints by santos22 11 months, 2 weeks ago