當前位置: 首頁>>代碼示例>>Python>>正文


Python base.MIMEBase方法代碼示例

本文整理匯總了Python中email.mime.base.MIMEBase方法的典型用法代碼示例。如果您正苦於以下問題:Python base.MIMEBase方法的具體用法?Python base.MIMEBase怎麽用?Python base.MIMEBase使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在email.mime.base的用法示例。


在下文中一共展示了base.MIMEBase方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_no_parts_in_a_multipart_with_none_epilogue

# 需要導入模塊: from email.mime import base [as 別名]
# 或者: from email.mime.base import MIMEBase [as 別名]
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--
''') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:test_email_renamed.py

示例2: test_no_parts_in_a_multipart_with_empty_epilogue

# 需要導入模塊: from email.mime import base [as 別名]
# 或者: from email.mime.base import MIMEBase [as 別名]
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--
''') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:22,代碼來源:test_email_renamed.py

示例3: test_one_part_in_a_multipart

# 需要導入模塊: from email.mime import base [as 別名]
# 或者: from email.mime.base import MIMEBase [as 別名]
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--
''') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:test_email_renamed.py

示例4: test_seq_parts_in_a_multipart_with_none_preamble

# 需要導入模塊: from email.mime import base [as 別名]
# 或者: from email.mime.base import MIMEBase [as 別名]
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--
''') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,代碼來源:test_email_renamed.py

示例5: test_seq_parts_in_a_multipart_with_none_epilogue

# 需要導入模塊: from email.mime import base [as 別名]
# 或者: from email.mime.base import MIMEBase [as 別名]
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--
''') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,代碼來源:test_email_renamed.py

示例6: test_seq_parts_in_a_multipart_with_empty_epilogue

# 需要導入模塊: from email.mime import base [as 別名]
# 或者: from email.mime.base import MIMEBase [as 別名]
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--
''') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,代碼來源:test_email_renamed.py

示例7: test__all__

# 需要導入模塊: from email.mime import base [as 別名]
# 或者: from email.mime.base import MIMEBase [as 別名]
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',
            ]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:test_email_renamed.py

示例8: test_no_parts_in_a_multipart_with_none_epilogue

# 需要導入模塊: from email.mime import base [as 別名]
# 或者: from email.mime.base import MIMEBase [as 別名]
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--''') 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:18,代碼來源:test_email_renamed.py

示例9: test_one_part_in_a_multipart

# 需要導入模塊: from email.mime import base [as 別名]
# 或者: from email.mime.base import MIMEBase [as 別名]
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--''') 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:25,代碼來源:test_email_renamed.py

示例10: test_seq_parts_in_a_multipart_with_none_preamble

# 需要導入模塊: from email.mime import base [as 別名]
# 或者: from email.mime.base import MIMEBase [as 別名]
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--''') 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:26,代碼來源:test_email_renamed.py

示例11: test_seq_parts_in_a_multipart_with_none_epilogue

# 需要導入模塊: from email.mime import base [as 別名]
# 或者: from email.mime.base import MIMEBase [as 別名]
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--''') 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:26,代碼來源:test_email_renamed.py

示例12: format

# 需要導入模塊: from email.mime import base [as 別名]
# 或者: from email.mime.base import MIMEBase [as 別名]
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"" 
開發者ID:abusesa,項目名稱:abusehelper,代碼行數:26,代碼來源:templates.py

示例13: send_email

# 需要導入模塊: from email.mime import base [as 別名]
# 或者: from email.mime.base import MIMEBase [as 別名]
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() 
開發者ID:google,項目名稱:starthinker,代碼行數:26,代碼來源:__init__.py

示例14: WOSendMail

# 需要導入模塊: from email.mime import base [as 別名]
# 或者: from email.mime.base import MIMEBase [as 別名]
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() 
開發者ID:WordOps,項目名稱:WordOps,代碼行數:26,代碼來源:sendmail.py

示例15: attach_sheets

# 需要導入模塊: from email.mime import base [as 別名]
# 或者: from email.mime.base import MIMEBase [as 別名]
def attach_sheets(*fns):
    '''Adds multipart spreadsheets.'''
    email = MIMEMultipart()
    for fn in fns:
        with open(fn, 'rb') as f:
            data = f.read()
        sheet = MIMEBase('application', 'vnd.ms-excel')
        sheet.set_payload(data)
        sheet.add_header('Content-Disposition', 'attachment; filename="%s"' % fn)
        email.attach(sheet)
    return email 
開發者ID:wdxtub,項目名稱:deep-learning-note,代碼行數:13,代碼來源:4_generate_email.py


注:本文中的email.mime.base.MIMEBase方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。