我已經使用下面的代碼來發送電子郵件,如同類似主題的帖子之一中建議的。但郵件尚未發送。有什麼建議麼?使用python執行shell郵件命令
import subprocess
recipient = '[email protected]'
subject = 'test'
body = 'testing mail through python'
def send_message(recipient, subject, body):
process = subprocess.Popen(['mail', '-s', subject, recipient],
stdin=subprocess.PIPE)
process.communicate(body)
print("sent the email")
您是否調用函數send_message()? –
'mail -s ...'是否在你的機器上的命令行上工作?如果不; 'subprocess'不會使它工作。您可以[使用'smtplib'發送電子郵件](http://stackoverflow.com/a/20787826/4279) – jfs