【发布时间】:2014-11-14 03:14:02
【问题描述】:
我在 Raspbian OS 上的 sendmail.sh 脚本能够成功发送电子邮件。但是,当从 python 脚本调用它时,我会收到 "mail: can not send message: process exited with non zero status" 错误消息。我已经通过手动运行sendmail.sh 验证了 ssmtp 配置正确。
sendmail.sh
#!/bin/bash
echo "test" | mail -s "test msg" myemailaddress
sendmail.sh 的权限是 777。sendmail.sh 和 sendmail.py 在同一个目录中。
sendmail.py
import os
import subprocess
subprocess.call(['./sendmail.sh'])
我用来运行python的命令-sudo python sendmail.py。
我不明白为什么会发生错误。显然,python 正在调用sendmail.sh,并且脚本设置了正确的权限。如果手动运行sendmail.sh,邮件发送正确。
【问题讨论】:
-
顺便说一句,请使用
check_call而不是call,除非您手动检查退出状态(显然,您没有)。 -
无论您遇到什么问题,chmod 777 都是错误且危险的。请立即将权限恢复为正常的权限(0755 在这里似乎很合适)。
-
调用脚本是否在不同的目录中运行?然后
./sendmail.sh将是“找不到文件”错误。 (为什么要将功能拆分为两个单独的脚本?)
标签: python bash email subprocess ssmtp