A email.cgi script
wonder
a at b.com
Sun Aug 15 07:12:04 EDT 2004
Hi,
I would like to write a python script that can be used in my website for
other people whoever browse my webside to send an email using my smtp
server. Is there any sample python script can do that?
Here is my python script, but it does not display To and From editbox in
the webpage for user type in their addresses:
#!/usr/bin/python
import smtplib, cgi, string
form = cgi.FieldStorage()
# Change the lines below to specify the TO and
# FROM addresses
toaddr = 'dest at abc.com'
fromaddr = ''
# Special form fields used by the email.cgi
# script
ack_url = form.getvalue('ack_url',None)
ack_text = form.getvalue('ack_text','Your submission was successful')
subject = form.getvalue('subject', '')
# form fields to skip
to_skip = ['ack_url', 'ack_text', 'subject', 'to']
# create the email headers
msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (fromaddr, toaddr,
subject)
for key in form.keys():
if string.lower(key) in to_skip: continue
msg = msg + "%s: %s\n\n" % (key, form.getvalue(key))
server = smtplib.SMTP('mail.xyx.com')
server.set_debuglevel(0)
server.sendmail(fromaddr, toaddr, msg)
server.quit()
if ack_url:
print "Location: %s" % (ack_url)
print
else:
print "Content-type: text/html"
print
print ack_text
More information about the Python-list
mailing list