def _make_payload(self): ctype, encoding = mimetypes.guess_type(self.file) if ctype is None or encoding is not None: # No guess could be made, or the file is encoded (compressed), so # use a generic bag-of-bits type. ctype = 'application/octet-stream' maintype, subtype = ctype.split('/', 1) with open(self.file, 'rb') as f: msg = MIMEBase(maintype, subtype, filename=self.filename_encoded) msg.set_payload(f.read()) self.encoder(msg) msg.set_unixfrom("X-Creator: Python Scripts") return msg