title: add excel file attachment when sending python email
body: <p>How do i add a document attachment when sending an email with python ?
  i get the email to send
  (please ignore: i am looping the email to send every 5 seconds, only for testing purposes, i want it to send every 30 min, just have to change 5 to 1800)</p>
  
  <p>here is my code so far. how do i attach a document from my computer?</p>
  
  <pre><code>#!/usr/bin/python
  
  import time
  import smtplib
  
  while True:
      TO = 'xxxx@gmail.com'
      SUBJECT = 'Python Email'
      TEXT = 'Here is the message'
  
      gmail_sender = 'xxxx@gmail.com'
      gmail_passwd = 'xxxx'
  
      server = smtplib.SMTP('smtp.gmail.com',587)
      server.ehlo()
      server.starttls()
      server.ehlo()
      server.login(gmail_sender, gmail_passwd)
      BODY = '\n'.join([
          'To: %s' % TO,
          'From: %s' % gmail_sender,
          'Subject:%s' % SUBJECT,
          '',
          TEXT
  
          ])
  
      try:
          server.sendmail(gmail_sender,[TO], BODY)
          print 'email sent'
      except:
          print 'error sending mail'
  
      time.sleep(5)
  
  server.quit()
  </code></pre>