我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用email.MIMEBase()。
def test__all__(self): module = __import__('email') all = module.__all__ all.sort() self.assertEqual(all, [ # Old names 'Charset', 'Encoders', 'Errors', 'Generator', 'Header', 'Iterators', 'MIMEAudio', 'MIMEBase', 'MIMEImage', 'MIMEMessage', 'MIMEMultipart', 'MIMENonMultipart', 'MIMEText', 'Message', 'Parser', 'Utils', 'base64MIME', # new names 'base64mime', 'charset', 'encoders', 'errors', 'generator', 'header', 'iterators', 'message', 'message_from_file', 'message_from_string', 'mime', 'parser', 'quopriMIME', 'quoprimime', 'utils', ])
def addAttachments(msg): attachments = [] lines = file_len("packages/mailing/attachments.txt") nb = random.randint(0, lines) for i in range(0, nb-1): rand = random.randint(1, lines) att = linecache.getline("packages/mailing/attachments.txt", rand).replace ("\n", "") attachments.append(att) if nb > 0: for f in attachments or []: with open(f, "rb") as fil: part = MIMEBase('application', "octet-stream") part.set_payload(fil.read()) Encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="%s"' %f) msg.attach(part) echoC(__name__, "Attachments attached") else: echoC(__name__, "No attachments") return msg