title: how to add the html file as an attachment in python?
body: <pre><code>matches = []
  for root, dirnames, filenames in os.walk('C:\Users\Desktop\ADI\New folder'):
      for filename in fnmatch.filter(filenames, '*.html'):
          matches.append(os.path.join(root, filename))
          page = filename
          #print filename
  
          server.quit()
  </code></pre>
  
  <p>In the above code : Firstly, I am finding the *.html files in a directory. I am finding it, it is working fine for me. Later I want to send that html file as an attached email to some person. I am failing in that. Can someone suggest me how to attach an file to the email and send it to the concerned person ?
  The above program is WORKING FINE in sending the email to the person, which just prints the name of the file in the email but not able to attach that email and send it.</p>
  
  <p>ERROR :</p>
  
  <pre><code>Traceback (most recent call last):
    File ".\task.py", line 39, in &lt;module&gt;
      server.sendmail(fromaddress,toaddress,msg.as_string())
    File "C:\Python27_3\lib\email\message.py", line 137, in as_string
      g.flatten(self, unixfrom=unixfrom)
    File "C:\Python27_3\lib\email\generator.py", line 83, in flatten
      self._write(msg)
    File "C:\Python27_3\lib\email\generator.py", line 115, in _write
      self._write_headers(msg)
    File "C:\Python27_3\lib\email\generator.py", line 164, in _write_headers
      v, maxlinelen=self._maxheaderlen, header_name=h).encode()
    File "C:\Python27_3\lib\email\header.py", line 410, in encode
      value = self._encode_chunks(newchunks, maxlinelen)
    File "C:\Python27_3\lib\email\header.py", line 370, in _encode_chunks
      _max_append(chunks, s, maxlinelen, extra)
    File "C:\Python27_3\lib\email\quoprimime.py", line 97, in _max_append
      L.append(s.lstrip())
  AttributeError: 'tuple' object has no attribute 'lstrip'
  </code></pre>