2013-04-13 16 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