title: python3 subprocess email attachment
body: <p>How to add attachment to subprocess in python 3  ?  I can send a mail without issue but not an attachment.</p>
  
  <pre><code>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")
  </code></pre>