0

sendmail.sh在 Raspbian OS 上的脚本能够成功发送电子邮件。但是当从 python 脚本调用它时,我收到一条"mail: can not send message: process exited with non zero status"错误消息。sendmail.sh我已经通过手动运行验证了 ssmtp 配置正确。

发送邮件.sh

#!/bin/bash
echo "test" | mail -s "test msg" myemailaddress

sendmail.sh 的权限为 777。 sendmail.sh 和 sendmail.py 位于同一目录中。

发送邮件.py

import os
import subprocess
subprocess.call(['./sendmail.sh'])

我用来运行 python 的命令 - sudo python sendmail.py

我不明白为什么会发生错误。显然,python 正在调用sendmail.sh,并且脚本设置了正确的权限。如果手动运行 sendmail.sh,则邮件发送正确。

4

2 回答 2

1

根本原因是ssmtp's给出的错误信息mail,这是最没有帮助的。

快速搜索它会显示http://www.raspberrypi.org/forums/viewtopic.php?t=46218&p=386393,其中包含以下内容:

尝试使用附加的 -d 参数运行命令以获取更多调试信息,以帮助确定问题的原因:

回声“测试” | mail -d -s "测试" myemail@mydomain.co.uk

<...>

我检查了我的错误日志,并注意到了这一点:

<日期时间> raspberrypi sSMTP[3477]: <​​一堆消息,包括显示根本原因的错误>

于 2014-11-14T03:36:47.713 回答
-2

你可以试试这个命令:

os.system('./sendmail.sh')
于 2014-11-14T03:44:51.427 回答