473,406 Members | 2,620 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,406 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 5575
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.