My sendmail.sh
script on Raspbian OS is able to successfully send an email. But when it's called from a python script, I get a "mail: can not send message: process exited with non zero status"
error message. I have verified that ssmtp is configured correctly by running sendmail.sh
by hand.
sendmail.sh
#!/bin/bash
echo "test" | mail -s "test msg" myemailaddress
permissions on sendmail.sh are 777. sendmail.sh and sendmail.py are in the same directory.
sendmail.py
import os
import subprocess
subprocess.call(['./sendmail.sh'])
The command I use to run the python - sudo python sendmail.py
.
I don't understand why the error occurs. Clearly, python is calling sendmail.sh
and the script has correct permissions set on it. If run sendmail.sh by hand, the mail is sent correctly.