473,287 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

smtp server simulation using Python

I have a (web) development computer w/o an SMTP server and want to test
form generated e-mail using a dummy SMTP server that delivers the mail
message to a file, or better yet, to a text editor instead of actually
sending it. Is it possible to extend the DebuggingServer class,and
override the process_message() method to accomplish this? If so, any
suggestions are appreciated.

Bill
Jun 17 '07 #1
3 5572
William Gill wrote:
I have a (web) development computer w/o an SMTP server and want to test
form generated e-mail using a dummy SMTP server that delivers the mail
message to a file, or better yet, to a text editor instead of actually
sending it. Is it possible to extend the DebuggingServer class,and
override the process_message() method to accomplish this? If so, any
suggestions are appreciated.
I would check out the smtpd module . It isn't documented, but the
source is fairly straightforward for subclassing.

- Josiah
Jun 18 '07 #2
I have a (web) development computer w/o an SMTP server and want to test
form generated e-mail using a dummy SMTP server that delivers the mail
message to a file, or better yet, to a text editor instead of actually
sending it.
Here's a quick and dirty script I use this for email testing purposes
- it's windows specific, but that's easy enough to change.

import smtpd, os, time, asyncore

class mailserver(smtpd.SMTPServer):
def __init__(self):
smtpd.SMTPServer.__init__(self, ('',25), None)
print 'Mailsink listening on port 25'

def process_message(self, peer, mailfrom, rcpttos, data):
basepath='c:\\.maildump'

print 'mail from: %s to: %s' %(mailfrom, repr(rcpttos))
for rcpt in rcpttos:
rcpt = rcpt.split('@')[0]
try:
os.mkdir(basepath+'\\'+rcpt)
except OSError:
pass

f =
file(basepath+'\\'+rcpt+'\\'+mailfrom+time.strftim e('%Y%m%d%H%M%S'),
'w')
f.write(data)
f.close()

def loop ():
x = mailserver()
try:
asyncore.loop(timeout=2)
except KeyboardInterrupt:
print'interrupt'
x.close()

if __name__=='__main__':
loop()
Jun 18 '07 #3


Dave Borne wrote:
>I have a (web) development computer w/o an SMTP server and want to test
form generated e-mail using a dummy SMTP server that delivers the mail
message to a file, or better yet, to a text editor instead of actually
sending it.

Here's a quick and dirty script I use this for email testing purposes
- it's windows specific, but that's easy enough to change.
Actually XP is where I need it.
Thanks

Bill
>
import smtpd, os, time, asyncore

class mailserver(smtpd.SMTPServer):
def __init__(self):
smtpd.SMTPServer.__init__(self, ('',25), None)
print 'Mailsink listening on port 25'

def process_message(self, peer, mailfrom, rcpttos, data):
basepath='c:\\.maildump'

print 'mail from: %s to: %s' %(mailfrom, repr(rcpttos))
for rcpt in rcpttos:
rcpt = rcpt.split('@')[0]
try:
os.mkdir(basepath+'\\'+rcpt)
except OSError:
pass

f =
file(basepath+'\\'+rcpt+'\\'+mailfrom+time.strftim e('%Y%m%d%H%M%S'),
'w')
f.write(data)
f.close()

def loop ():
x = mailserver()
try:
asyncore.loop(timeout=2)
except KeyboardInterrupt:
print'interrupt'
x.close()

if __name__=='__main__':
loop()
Jun 24 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David Hughes | last post by:
I wonder if anyone can help me resolve this problem. Although my ISP (One and One) provides the facility to run Python 2.2 CGI programs, their technical support people don't seem to have any Python...
7
by: Nancy | last post by:
Hi, Is there any one knows, if I want to use mod_python to handle my html form, I must have a SMTP server on my PC(winxp pro)? Where can I get a free SMTP server? I cann't follow mod_python's...
21
by: Nancy | last post by:
Hi, Guys, Is there any other way to use python or mod_python writing a web page? I mean, not use "form.py/email", no SMTP server. <form action="form.py/email" method="POST"> ... Thanks a lot. ...
8
by: JZ | last post by:
I cannot find out what is the problem with my Python. I cannot join to smtp host. > python Python 2.3.4 (#1, Jun 22 2004, 04:42:42) on linux2 Type "help", "copyright", "credits" or "license"...
15
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do...
19
by: Nicolas Pernetty | last post by:
Hello, I'm looking for any work/paper/ressource about continuous system simulation using Python or any similar object oriented languages (or even UML theory !). I'm aware of SimPy for...
11
by: fdu.xiaojf | last post by:
Hi, I just want to send a very simple email from within python. I think the standard module of smtpd in python can do this, but I haven't found documents about how to use it after googleing....
1
by: William Connery | last post by:
Hi, I have a small python program with e-mail capabilities that I have pieced together from code snippets found on the internet. The program uses the smtplib module to successfully send an...
8
by: _spitFIRE | last post by:
Is it possible to run a SMTP server that sends mail to recipients using standard libraries, without using twisted framework, and also without using any relay server?
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.