#!/usr/bin/env python import os def sendmail(send_to, send_from, subject, body): """ form response string in the form of a sendmail session and pipe it to sendmail #TODO: consider using smtplib or similar mailing library here #http://www.python.org/doc/current/lib/module-smtplib.html @rtype: int @returns exit status of mail process """ MAIL = "/usr/sbin/sendmail" response = "To: " + str(send_to) + \ "\nFrom: " + str(send_from) + \ "\nSubject: "+ str(subject) + \ "\n\n" + str(body) + "\n" p = os.popen("%s -t" % MAIL, 'w') p.write(response) exitcode = p.close() if exitcode == None: """ From the docs: The exit status of the command (encoded in the format specified for wait()) is available as the return value of the close() method of the file object, except that when the exit status is zero (termination without errors), None is returned. http://docs.python.org/lib/os-newstreams.html """ return 0 else: return exitcode