2013-04-13 18 views
0

我在外壳使用邮件命令发送不起作用的shell命令电子邮件:用于发送电子邮件的python子呼叫

echo "abc" | mail -s "Subject" [email protected] 

我想用在Python此命令,所以我写了以下内容:

call("echo abc" "|" "mail", "-s Subject", "[email protected]", shell=True) 

然后它给了我下面的错误:

Original exception was: 
Traceback (most recent call last): 
    File "email.py", line 7, in <module> 
    call("mail", "-s", "Subject", "[email protected]", shell=True) 
    File "/usr/lib/python2.7/subprocess.py", line 493, in call 
    return Popen(*popenargs, **kwargs).wait() 
    File "/usr/lib/python2.7/subprocess.py", line 629, in __init__ 
    raise TypeError("bufsize must be an integer") 
TypeError: bufsize must be an integer 

,这是什么原因呢?

回答

1

尝试调用call方法这样

call(["mail", "-s", "'Subject'", "[email protected]"], shell=True) 

第2部分:

sudo touch /var/mail/<username> 
sudo chown <username>:mail /var/mail/<username> 
sudo chmod o-r /var/mail/<username> 
sudo chmod g+rw /var/mail/<username> 

here

+0

采取我实际上应该键入:调用([ “邮件”,“ - s Subject“,”[email protected]“],shell = True)。但它给出了另一个错误: 无法打开邮箱/ var/mail/rex:权限被拒绝 – drdot

+0

所以你现在的方法调用是正确的。当你从* shell和* same *用户运行它时,这个命令是什么。这个*/var/mail/rex *的权限是否正确? – unhacked

+0

是的。壳牌没有问题。 – drdot