i try to rewrite popen2 to subprocess.Popen. And I get error.
My code:
cmd = '/usr/sbin/sendmail -t -i'
if len(sys.argv) == 3:
cmd += " -f%s" % sys.argv[2]
# OLD CODE =======================
#(out, s) = popen2(cmd)
#s.write(data)
#s.close()
# ================================
# NEW CODE =======================
p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, close_fds=True)
(out, s) = (p.stdin, p.stdout)
s.write(data)
s.close()
sys.stdout.flush()
In apache error_log I get error:
Traceback (most recent call last):
File "/opt/php-secure-sendmail/secure_sendmail.py", line 80, in <module>
s.write(data)
IOError: File not open for writing
sendmail: fatal: test@serve.tld(10000): No recipient addresses found in message header
plesk sendmail[2576]: sendmail unsuccessfully finished with exitcode 75
Maybe somebody has idea how figure out this code?