Kevan
#!/tools/net/bin/python
import sys,os,string
import html,cgi
sendmail_command = '/usr/lib/sendmail -t'
# -----------------------------------------------------------------------------
def main ():
# Read the cgi environment
#
cgi_env = cgi.CGI ()
# Output the mime header for the client
#
cgi.mime_content_header (sys.stdout,'text/html')
# Act on request type
#
if cgi_env.request_method == 'GET':
# Create an html object for writing the output
#
out = html.html_write (sys.stdout)
# Output a standard begining
#
out.std_start ('','Mail A User')
# Create the mail form
#
out.form_begin ('POST','http://www:8080/cgi/mail')
out.horizontal_rule ()
out.pre_begin ()
out.write ('From :')
out.form_text_line ('from','',60,0)
out.break_line ()
out.write ('To :')
out.form_text_line ('to','',60,0)
out.break_line ()
out.write ('Subject :')
out.form_text_line ('subject','',60,0)
out.break_line ()
out.form_text_area ('message','',15,70)
out.pre_end ()
out.form_submit ('Send Mail')
out.form_reset ('Clear')
out.horizontal_rule ()
# End the form
#
out.form_end ()
out.finish()
elif cgi_env.request_method == 'POST':
# Get the form values from the cgi environment
#
form = cgi.Form(cgi_env)
# Create sendmail message
#
sendmail_input = []
sendmail_input.append ('From: '+form.value('from')+'\n')
sendmail_input.append ('To: '+form.value('to')+'\n')
sendmail_input.append ('Subject: '+form.value('subject')+'\n')
sendmail_input.append ('\n')
sendmail_input.append (form.value('message'))
sendmail_input.append ('\n')
# Send the message using sendmail
#
pd = os.popen (sendmail_command,'w')
for line in sendmail_input:
pd.write (line)
status = pd.close ()
# Output mail sending return status
#
out = html.html_write (sys.stdout)
out.std_start ('','Mail Response')
if status == None:
out.writeline ('Message sent ok')
else:
out.writeline ('Error sending message')
out.finish ()
else:
pass
# -----------------------------------------------------------------------------
main()