-   Programming (
-   -   Apache, Python and sendmail (

hurricane 06-06-2005 10:59 AM

Apache, Python and sendmail

i have a python script running on an apache server. what i want is to be able to call sendmail from the python script from the webbrowser.

here is my code.

def sendMail(name, email) :

MAIL = "/usr/sbin/sendmail"
ADDRESS = '%s'%(email)
# get the email message from a file
mssg = "Hello %s, \n This is a test email"%(username)

# open a pipe to the mail program and
# write the data to the pipe
p = os.popen("%s %s" %(MAIL,ADDRESS), 'w')
exitcode = p.close()
if exitcode:
print "Exit code: %s" % exitcode

this works in a python shell but not from the webbrowser. i suspect the path to sendmail is the problem.

how do i get sendmail to work from apache, do i have to add it to some sort of path variable? does apache have its own sendmail functions i can use? or python it self have a better alternative.

im new to all of this so please be gentle :)


rose_bud4201 06-06-2005 11:26 AM

Hmm...python shouldn't really have any trouble accessing sendmail, when run as a cgi program from cgi-bin. Are you getting any error messages, or is it simply not working? Do you have python's debugging turned on

import cgitb
cgitb.enable(display=1) #On, 0 is off

and is it giving any helpful information?

hurricane 06-07-2005 04:31 AM

no will try that tho and see what i get,

i get an exit code of

"Exit code: 17152"

i added the debug stuff at the top of the page and i dont get an error page up as i would expect if something went wrong

All times are GMT -5. The time now is 07:29 PM.