如何在python 3中添加附件到子进程?我可以发送邮件,但不是附件。
import subprocess
recipient = 'test@test.com'
subject = 'test'
body = 'testing mail through python'
path = '/home/Errors.log'
def send_message(recipient, subject, body):
try:
process = subprocess.Popen(['mail', '-s', subject, recipient, '-a', path],
stdin=subprocess.PIPE)
except Exception as error:
print (error)
process.communicate(body.encode('ascii'))
send_message(recipient, subject, body)
print("sent the email")