Python email.mime.base.MIMEBase() Examples
The following are 30
code examples of email.mime.base.MIMEBase().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
email.mime.base
, or try the search function
.
Example #1
Source File: test_email_renamed.py From ironpython2 with Apache License 2.0 | 8 votes |
def test_one_part_in_a_multipart(self): eq = self.ndiffAssertEqual outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.set_boundary('BOUNDARY') msg = MIMEText('hello world') outer.attach(msg) eq(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit hello world --BOUNDARY-- ''')
Example #2
Source File: sendmail.py From WordOps with MIT License | 7 votes |
def WOSendMail(send_from, send_to, subject, text, files, server="localhost", port=587, username='', password='', isTls=True): msg = MIMEMultipart() msg['From'] = send_from msg['To'] = send_to msg['Date'] = formatdate(localtime=True) msg['Subject'] = subject msg.attach(MIMEText(text)) for f in files: part = MIMEBase('application', "octet-stream") part.set_payload(open(f, "rb").read()) encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="{0}"' .format(os.path.basename(f))) msg.attach(part) smtp = smtplib.SMTP(server, port) if isTls: smtp.starttls() smtp.sendmail(send_from, send_to, msg.as_string()) smtp.quit()
Example #3
Source File: test_email.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_seq_parts_in_a_multipart_with_none_preamble(self): eq = self.ndiffAssertEqual outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.preamble = None msg = MIMEText('hello world') outer.attach(msg) outer.set_boundary('BOUNDARY') eq(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit hello world --BOUNDARY-- ''')
Example #4
Source File: test_email_renamed.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_seq_parts_in_a_multipart_with_none_preamble(self): eq = self.ndiffAssertEqual outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.preamble = None msg = MIMEText('hello world') outer.attach(msg) outer.set_boundary('BOUNDARY') eq(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit hello world --BOUNDARY-- ''')
Example #5
Source File: test_email_renamed.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_seq_parts_in_a_multipart_with_none_epilogue(self): eq = self.ndiffAssertEqual outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.epilogue = None msg = MIMEText('hello world') outer.attach(msg) outer.set_boundary('BOUNDARY') eq(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit hello world --BOUNDARY-- ''')
Example #6
Source File: test_email_renamed.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_no_parts_in_a_multipart_with_empty_epilogue(self): outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.preamble = '' outer.epilogue = '' outer.set_boundary('BOUNDARY') self.ndiffAssertEqual(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY --BOUNDARY-- ''')
Example #7
Source File: test_email_renamed.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_no_parts_in_a_multipart_with_none_epilogue(self): outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.set_boundary('BOUNDARY') self.ndiffAssertEqual(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY --BOUNDARY-- ''')
Example #8
Source File: test_email_renamed.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_seq_parts_in_a_multipart_with_empty_epilogue(self): eq = self.ndiffAssertEqual outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.epilogue = '' msg = MIMEText('hello world') outer.attach(msg) outer.set_boundary('BOUNDARY') eq(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit hello world --BOUNDARY-- ''')
Example #9
Source File: test_email_renamed.py From ironpython2 with Apache License 2.0 | 6 votes |
def test__all__(self): module = __import__('email') # Can't use sorted() here due to Python 2.3 compatibility 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', ])
Example #10
Source File: test_email_renamed.py From BinderFilter with MIT License | 6 votes |
def test_no_parts_in_a_multipart_with_none_epilogue(self): outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.set_boundary('BOUNDARY') self.ndiffAssertEqual(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY --BOUNDARY--''')
Example #11
Source File: test_email_renamed.py From BinderFilter with MIT License | 6 votes |
def test_no_parts_in_a_multipart_with_empty_epilogue(self): outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.preamble = '' outer.epilogue = '' outer.set_boundary('BOUNDARY') self.ndiffAssertEqual(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY --BOUNDARY-- ''')
Example #12
Source File: test_email_renamed.py From BinderFilter with MIT License | 6 votes |
def test_one_part_in_a_multipart(self): eq = self.ndiffAssertEqual outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.set_boundary('BOUNDARY') msg = MIMEText('hello world') outer.attach(msg) eq(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit hello world --BOUNDARY--''')
Example #13
Source File: test_email_renamed.py From BinderFilter with MIT License | 6 votes |
def test_seq_parts_in_a_multipart_with_none_preamble(self): eq = self.ndiffAssertEqual outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.preamble = None msg = MIMEText('hello world') outer.attach(msg) outer.set_boundary('BOUNDARY') eq(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit hello world --BOUNDARY--''')
Example #14
Source File: test_email_renamed.py From BinderFilter with MIT License | 6 votes |
def test_seq_parts_in_a_multipart_with_none_epilogue(self): eq = self.ndiffAssertEqual outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.epilogue = None msg = MIMEText('hello world') outer.attach(msg) outer.set_boundary('BOUNDARY') eq(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit hello world --BOUNDARY--''')
Example #15
Source File: test_email_renamed.py From BinderFilter with MIT License | 6 votes |
def test__all__(self): module = __import__('email') # Can't use sorted() here due to Python 2.3 compatibility 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', ])
Example #16
Source File: test_email_renamed.py From oss-ftp with MIT License | 6 votes |
def test_no_parts_in_a_multipart_with_none_epilogue(self): outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.set_boundary('BOUNDARY') self.ndiffAssertEqual(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY --BOUNDARY-- ''')
Example #17
Source File: test_email_renamed.py From oss-ftp with MIT License | 6 votes |
def test_no_parts_in_a_multipart_with_empty_epilogue(self): outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.preamble = '' outer.epilogue = '' outer.set_boundary('BOUNDARY') self.ndiffAssertEqual(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY --BOUNDARY-- ''')
Example #18
Source File: test_email_renamed.py From oss-ftp with MIT License | 6 votes |
def test_one_part_in_a_multipart(self): eq = self.ndiffAssertEqual outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.set_boundary('BOUNDARY') msg = MIMEText('hello world') outer.attach(msg) eq(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit hello world --BOUNDARY-- ''')
Example #19
Source File: test_email_renamed.py From oss-ftp with MIT License | 6 votes |
def test_seq_parts_in_a_multipart_with_none_preamble(self): eq = self.ndiffAssertEqual outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.preamble = None msg = MIMEText('hello world') outer.attach(msg) outer.set_boundary('BOUNDARY') eq(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit hello world --BOUNDARY-- ''')
Example #20
Source File: test_email_renamed.py From oss-ftp with MIT License | 6 votes |
def test_seq_parts_in_a_multipart_with_none_epilogue(self): eq = self.ndiffAssertEqual outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.epilogue = None msg = MIMEText('hello world') outer.attach(msg) outer.set_boundary('BOUNDARY') eq(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit hello world --BOUNDARY-- ''')
Example #21
Source File: test_email_renamed.py From oss-ftp with MIT License | 6 votes |
def test_seq_parts_in_a_multipart_with_empty_epilogue(self): eq = self.ndiffAssertEqual outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.epilogue = '' msg = MIMEText('hello world') outer.attach(msg) outer.set_boundary('BOUNDARY') eq(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit hello world --BOUNDARY-- ''')
Example #22
Source File: test_email_renamed.py From oss-ftp with MIT License | 6 votes |
def test__all__(self): module = __import__('email') # Can't use sorted() here due to Python 2.3 compatibility 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', ])
Example #23
Source File: templates.py From abusehelper with MIT License | 6 votes |
def format(self, parts, events, filename, *args): prefix, ext = os.path.splitext(filename) if ext.lower() == ".zip": zip_name = filename raw_name = prefix else: zip_name = filename + ".zip" raw_name = filename data = self.formatter.format(parts, events, *args) memfile = StringIO() zipped = zipfile.ZipFile(memfile, 'w', zipfile.ZIP_DEFLATED) zipped.writestr(raw_name, data.encode("utf-8")) zipped.close() memfile.flush() memfile.seek(0) part = MIMEBase("application", "zip") part.set_payload(memfile.read()) encode_base64(part) part.add_header("Content-Disposition", "attachment", filename=zip_name) parts.append(part) return u""
Example #24
Source File: __init__.py From starthinker with Apache License 2.0 | 6 votes |
def send_email(auth, email_to, email_from, email_cc, subject, text, html=None, attachment_filename=None, attachment_rows=None): if project.verbose: print('SENDING EMAIL', email_to) message = MIMEMultipart('alternative') message.set_charset('utf8') message['to'] = email_to message['cc'] = email_cc message['from'] = email_from message['subject'] = subject message.attach(MIMEText(text, 'plain', 'UTF-8')) if html: message.attach(MIMEText(html, 'html', 'UTF-8')) if attachment_filename and attachment_rows: attachment = MIMEBase("text", "csv") attachment.set_payload(rows_to_csv(attachment_rows).read()) attachment.add_header('Content-Disposition', 'attachment',filename=attachment_filename) encode_base64(attachment) message.attach(attachment) #API_Gmail(auth).users().messages().send(userId='me', body={'raw': base64.urlsafe_b64encode(message.as_string())}).execute() API_Gmail(auth).users().messages().send(userId='me', body={'raw': base64.urlsafe_b64encode(message.as_bytes()).decode()}).execute()
Example #25
Source File: test_email.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_no_parts_in_a_multipart_with_none_epilogue(self): outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.set_boundary('BOUNDARY') self.ndiffAssertEqual(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY --BOUNDARY-- ''')
Example #26
Source File: test_email.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_no_parts_in_a_multipart_with_empty_epilogue(self): outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.preamble = '' outer.epilogue = '' outer.set_boundary('BOUNDARY') self.ndiffAssertEqual(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY --BOUNDARY-- ''')
Example #27
Source File: test_email.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_one_part_in_a_multipart(self): eq = self.ndiffAssertEqual outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.set_boundary('BOUNDARY') msg = MIMEText('hello world') outer.attach(msg) eq(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit hello world --BOUNDARY-- ''')
Example #28
Source File: test_email_renamed.py From BinderFilter with MIT License | 6 votes |
def test_seq_parts_in_a_multipart_with_empty_epilogue(self): eq = self.ndiffAssertEqual outer = MIMEBase('multipart', 'mixed') outer['Subject'] = 'A subject' outer['To'] = 'aperson@dom.ain' outer['From'] = 'bperson@dom.ain' outer.epilogue = '' msg = MIMEText('hello world') outer.attach(msg) outer.set_boundary('BOUNDARY') eq(outer.as_string(), '''\ Content-Type: multipart/mixed; boundary="BOUNDARY" MIME-Version: 1.0 Subject: A subject To: aperson@dom.ain From: bperson@dom.ain --BOUNDARY Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit hello world --BOUNDARY-- ''')
Example #29
Source File: crashreporter.py From crashreporter with MIT License | 5 votes |
def smtp_submit(self, subject, body, attachments=None): smtp = self._smtp msg = MIMEMultipart() if isinstance(smtp['recipients'], list) or isinstance(smtp['recipients'], tuple): msg['To'] = ', '.join(smtp['recipients']) else: msg['To'] = smtp['recipients'] msg['From'] = smtp['from'] msg['Subject'] = subject # Add the body of the message msg.attach(MIMEText(body, 'html')) # Add any attachments if attachments: for attachment in attachments: part = MIMEBase('application', 'octet-stream') part.set_payload(open(attachments, 'rb').read()) encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(attachment)) msg.attach(part) try: ms = smtplib.SMTP(smtp['host'], smtp['port'], timeout=smtp['timeout']) ms.ehlo() ms.starttls() ms.ehlo() ms.login(smtp['user'], smtp['passwd']) ms.sendmail(smtp['from'], smtp['recipients'], msg.as_string()) ms.close() except Exception as e: self.logger.error('CrashReporter: %s' % e) return False return True
Example #30
Source File: nonmultipart.py From pmatic with GNU General Public License v2.0 | 5 votes |
def attach(self, payload): # The public API prohibits attaching multiple subparts to MIMEBase # derived subtypes since none of them are, by definition, of content # type multipart/* raise errors.MultipartConversionError( 'Cannot attach additional subparts to non-multipart/*')