我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用email.MIMEBase.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 sendEmailPrintable(textToSend,fileToSend,addressToSend, pathToFile, subject): msg = MIMEMultipart() msg['From'] = printableFromAddress msg['To'] = addressToSend msg['Subject'] = subject msg.attach(MIMEText(textToSend,'plain')) attachment = open(pathToFile+fileToSend, "rb") part = MIMEBase('application','octet-stream') part.set_payload((attachment).read()) encoders.encode_base64(part) part.add_header('Content-Disposition', "attachment; filename= %s" % fileToSend) msg.attach(part) server = smtplib.SMTP(emailServer, 25) #server.starttls() text = msg.as_string() server.sendmail(printableFromAddress, addressToSend.split(","), text) server.quit attachment.close()
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