How to lunch webpage without using SMTP server?

Nancy wxling3 at hotmail.com
Sat Jul 24 20:33:05 EDT 2004


Hi, Guys,

   Many thanks for all messages! I am new to Python. I wonder whether
many suggestions run in different direction. (Sorry about my English,
may not good enough too.)

   I am trying to following the example on 
   http://www.modpython.org/live/current/doc-html/tut-pub.html  
   
  First, I don't have permission to access a SMTP server.
  Second, I don't want to install any SMTP server on my PC.
  Third, I want my webpage/form to collect the data provided by users
and let my *.py file to handle these data, such as connect to the
database, select some data, update, etc. that is, something likes
following,
   <form action="myfile.py" method="POST" ...>
   

  Then what should I do? How can I achieve that?
   The following code is a copy from above website.
 
  <html>
      Please provide feedback below:
  <p>
  <form action="form.py/email" method="POST">

      Name:    <input type="text" name="name"><br>
      Email:   <input type="text" name="email"><br>
      Comment: <textarea name="comment" rows=4 cols=20></textarea><br>
      <input type="submit">

  </form>
  </html>

Note the action element of the <form> tag points to form.py/email. We
are going to create a file called form.py, like this:


import smtplib

WEBMASTER = "webmaster"   # webmaster e-mail
SMTP_SERVER = "localhost" # your SMTP server

def email(req, name, email, comment):

    # make sure the user provided all the parameters
    if not (name and email and comment):
        return "A required parameter is missing, \
               please go back and correct the error"

    # create the message text
    msg = """\
From: %s
Subject: feedback
To: %s

I have the following comment:

%s

Thank You,

%s

""" % (email, WEBMASTER, comment, name)

    # send it out
    conn = smtplib.SMTP(SMTP_SERVER)
    conn.sendmail(email, [WEBMASTER], msg)
    conn.quit()

    # provide feedback to the user
    s = """\
<html>

Dear %s,<br>
Thank You for your kind comments, we
will get back to you shortly.

</html>""" % name

    return s

When the user clicks the Submit button, the publisher handler will
load the email function in the form module, passing it the form fields
as keyword arguments. It will also pass the request object as req.

Note that you do not have to have req as one of the arguments if you
do not need it. The publisher handler is smart enough to pass your
function only those arguments that it will accept.


   Thanks again.

Nancy



More information about the Python-list mailing list