gpt4 book ai didi

python - 使用python执行shell邮件命令

转载 作者:太空狗 更新时间:2023-10-29 22:11:09 27 4
gpt4 key购买 nike

我已经使用以下代码发送了一封电子邮件,正如其中一篇关于类似主题的帖子中所建议的那样。但是邮件一直没有发出。有什么建议吗?

import subprocess
recipient = 'xxxxx@gmail.com'
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")

最佳答案

你的函数可能没有被调用,试试这个代码:

import subprocess

recipient = 'xxxxx@gmail.com'
subject = 'test'
body = 'testing mail through python'

def send_message(recipient, subject, body):
try:
process = subprocess.Popen(['mail', '-s', subject, recipient],
stdin=subprocess.PIPE)
except Exception, error:
print error
process.communicate(body)

send_message(recipient, subject, body)

print("sent the email")

可能有效。祝你好运。

关于python - 使用python执行shell邮件命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27874102/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com