python3子进程电子邮件附件

时间:2016-05-10 14:21:39

标签: python email python-3.x subprocess

如何在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")

0 个答案:

没有答案