code: def get_attachment(self, file_path):
          '''Get file as MIMEBase message'''
  
          try:
              file_ = open(file_path, 'rb')
              attachment = MIMEBase('application', 'octet-stream')
              attachment.set_payload(file_.read())
              file_.close()
              encoders.encode_base64(attachment)
  
              attachment.add_header('Content-Disposition', 'attachment',
                                    filename=os.path.basename(file_path))
              return attachment
          except IOError:
              traceback.print_exc()
              message = ('The requested file could not be read. Maybe wrong '
                         'permissions?')
              print >> sys.stderr, message
              sys.exit(6f get_attachment(self, file_path):
          '''Get file as MIMEBase message'''
  
          try:
              file_ = open(file_path, 'rb')
              attachment = MIMEBase('application', 'octet-stream')
              attachment.set_payload(file_.read())
              file_.close()
              encoders.encode_base64(attachment)
  
              attachment.add_header('Content-Disposition', 'attachment',
                                    filename=os.path.basename(file_path))
              return attachment
          except IOError:
              traceback.print_exc()
              message = ('The requested file could not be read. Maybe wrong '
                         'permissions?')
              print >> sys.stderr, message
              sys.exit(6)
docs: Get file as MIMEBase message