我已经使用下面的代码来发送电子邮件,如同类似主题的帖子之一中建议的。但邮件尚未发送。有什么建议么?使用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