SMTP sink server

 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

  1. Email queue in DB by fish2000 2 years, 1 month ago
  2. Better debugging mail server by yourcelf 1 year, 3 months ago
  3. SMTP sink server: prettier output by huwshimi 2 years ago
  4. Testing Email Registration by osborn.steven 3 years, 2 months ago
  5. DKIM Email Backend by DrMeers 2 years, 1 month ago

Comments

mboersma (on March 12, 2007):

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!

#

twinsant (on March 20, 2007):

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.

#

zgoda (on July 13, 2007):

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:

def run(port=25):
    foo = EmlServer(('localhost', port), None)

and later in line 26 and later:

try:
    port = int(sys.argv[1])
except IndexError:
    sys.exit("Usage: smtpsink.py <port>")
run(port)

Of course, you have to import sys at the top of the module too.

#

twinsant (on August 1, 2007):

I found another one: SMTP Mailsink

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440690

#

arne (on August 27, 2007):

very useful, thanks for sharing this snippet

#

vung (on December 23, 2007):

Line 12 should be: f.close()

#

zero (on February 12, 2008):

instead of writing an .eml you can directly send your mail to the built in python mail server. on a shell do:

sudo /usr/lib/python2.4/smtpd.py -n -c DebuggingServer localhost:25

then send your mails to localhost:25 and you will see the results immediately :-)

#

hasenj (on September 21, 2008):

thank you man, this is awesome!! helps so much!

#

huwshimi (on May 5, 2010):

I've added a version with nicer, more verbose terminal messages: http://www.djangosnippets.org/snippets/2010/

#

blackevening (on January 29, 2012):

[HTML_REMOVED]

[HTML_REMOVED] [HTML_REMOVED][HTML_REMOVED]nfl new jerseys 2011[HTML_REMOVED][HTML_REMOVED][HTML_REMOVED] [HTML_REMOVED][HTML_REMOVED]low price nfl jerseys[HTML_REMOVED][HTML_REMOVED][HTML_REMOVED] [HTML_REMOVED][HTML_REMOVED]buy nfl women jerseys[HTML_REMOVED][HTML_REMOVED][HTML_REMOVED] [HTML_REMOVED][HTML_REMOVED]nfl women jerseys for sale[HTML_REMOVED][HTML_REMOVED][HTML_REMOVED] [HTML_REMOVED][HTML_REMOVED]youth nfl jersey[HTML_REMOVED][HTML_REMOVED][HTML_REMOVED] .The largest advantage, all the more so as compared to connecting through wholesale providers, is having access to education.Retail store industry interactions often accommodate seminars in addition to conventions, or they're going to keep you abreast of other organizations which can be holding tutorials and events.(By the best way, conventions will be another place and hook upwards with wholesalers.)[HTML_REMOVED] [HTML_REMOVED] Retail field associations help keep you over the current news from with your industry.It's very important to keep up to par with what is going on in your own industry, or else you can receive left inside the dust as the competition pass a person by.You will most likely receive valuable how-to's to better your earnings, and we could all use somewhat more profit, wouldn't we? [HTML_REMOVED] [HTML_REMOVED] Eventually, many of the organizations are usually great regions to circle with other people who run businesses in an individual's industry

#

chunhairr (on March 7, 2012):

Hello, everybody, the good shoping place, the new season approaching, click in. Welcome to ==== http://www.proxy4biz.com == Air Jordan (1-24) shoes $35 Jordan (1-22)&2009 shoes $45 Nike shox (R4, NZ, OZ, TL1, TL2, TL3) $35 Handbags ( Coach Lv fendi D&G) $30 T-shirts (polo, ed hardy, lacoste) $14 Jean (True Religion, ed hardy, coogi)$34 Sunglasses ( Oakey, coach, Gucci, Armaini)$15 New era cap $16 Biki ni (Ed hardy, polo) $18
FREE SHIPPING http://www.proxy4biz.com

http://www.proxy4biz.com

http://www.proxy4biz.com

http://www.proxy4biz.com http://www.proxy4biz.com

http://www.proxy4biz.com

http://www.proxy4biz.com

http://www.proxy4biz.com

===( http://www.proxy4biz.com )===

===( http://www.proxy4biz.com )===

===( http://www.proxy4biz.com )===

===( http://www.proxy4biz.com )===

===( http://www.proxy4biz.com )===

===( http://www.proxy4biz.com )=== This is a shopping paradise We need your support and trust 、

#

(Forgotten your password?)