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


Python MIMEText.MIMEText方法代碼示例

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


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

示例1: test_header_splitter

# 需要導入模塊: from email import MIMEText [as 別名]
# 或者: from email.MIMEText import MIMEText [as 別名]
def test_header_splitter(self):
        eq = self.ndiffAssertEqual
        msg = MIMEText('')
        # It'd be great if we could use add_header() here, but that doesn't
        # guarantee an order of the parameters.
        msg['X-Foobar-Spoink-Defrobnit'] = (
            'wasnipoop; giraffes="very-long-necked-animals"; '
            'spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"')
        sfp = StringIO()
        g = Generator(sfp)
        g.flatten(msg)
        eq(sfp.getvalue(), '''\
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Foobar-Spoink-Defrobnit: wasnipoop; giraffes="very-long-necked-animals";
 spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"

''') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_email.py

示例2: test_seq_parts_in_a_multipart_with_empty_preamble

# 需要導入模塊: from email import MIMEText [as 別名]
# 或者: from email.MIMEText import MIMEText [as 別名]
def test_seq_parts_in_a_multipart_with_empty_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 = ''
        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,代碼行數:27,代碼來源:test_email.py

示例3: test_add_header

# 需要導入模塊: from email import MIMEText [as 別名]
# 或者: from email.MIMEText import MIMEText [as 別名]
def test_add_header(self):
        eq = self.assertEqual
        self._im.add_header('Content-Disposition', 'attachment',
                            filename='dingusfish.gif')
        eq(self._im['content-disposition'],
           'attachment; filename="dingusfish.gif"')
        eq(self._im.get_params(header='content-disposition'),
           [('attachment', ''), ('filename', 'dingusfish.gif')])
        eq(self._im.get_param('filename', header='content-disposition'),
           'dingusfish.gif')
        missing = []
        eq(self._im.get_param('attachment', header='content-disposition'), '')
        self.assertIs(self._im.get_param('foo', failobj=missing,
                                         header='content-disposition'), missing)
        # Try some missing stuff
        self.assertIs(self._im.get_param('foobar', missing), missing)
        self.assertIs(self._im.get_param('attachment', missing,
                                         header='foobar'), missing)



# Test the basic MIMEText class 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:24,代碼來源:test_email.py

示例4: test_seq_parts_in_a_multipart_with_none_preamble

# 需要導入模塊: from email import MIMEText [as 別名]
# 或者: from email.MIMEText import MIMEText [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.py

示例5: test_seq_parts_in_a_multipart_with_none_epilogue

# 需要導入模塊: from email import MIMEText [as 別名]
# 或者: from email.MIMEText import MIMEText [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.py

示例6: test_seq_parts_in_a_multipart_with_empty_epilogue

# 需要導入模塊: from email import MIMEText [as 別名]
# 或者: from email.MIMEText import MIMEText [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.py

示例7: test__all__

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

示例8: test_add_header

# 需要導入模塊: from email import MIMEText [as 別名]
# 或者: from email.MIMEText import MIMEText [as 別名]
def test_add_header(self):
        eq = self.assertEqual
        unless = self.assertTrue
        self._im.add_header('Content-Disposition', 'attachment',
                            filename='dingusfish.gif')
        eq(self._im['content-disposition'],
           'attachment; filename="dingusfish.gif"')
        eq(self._im.get_params(header='content-disposition'),
           [('attachment', ''), ('filename', 'dingusfish.gif')])
        eq(self._im.get_param('filename', header='content-disposition'),
           'dingusfish.gif')
        missing = []
        eq(self._im.get_param('attachment', header='content-disposition'), '')
        unless(self._im.get_param('foo', failobj=missing,
                                  header='content-disposition') is missing)
        # Try some missing stuff
        unless(self._im.get_param('foobar', missing) is missing)
        unless(self._im.get_param('attachment', missing,
                                  header='foobar') is missing)



# Test the basic MIMEText class 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:25,代碼來源:test_email.py

示例9: test_seq_parts_in_a_multipart_with_none_preamble

# 需要導入模塊: from email import MIMEText [as 別名]
# 或者: from email.MIMEText import MIMEText [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.py

示例10: test_seq_parts_in_a_multipart_with_none_epilogue

# 需要導入模塊: from email import MIMEText [as 別名]
# 或者: from email.MIMEText import MIMEText [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.py

示例11: send_e_mail

# 需要導入模塊: from email import MIMEText [as 別名]
# 或者: from email.MIMEText import MIMEText [as 別名]
def send_e_mail(subject):
    """
    send an e mail from the Cisco network to anyone -
    Note: This example uses from address as a Cisco server, Change the domain to your SMTP server to send email from your domain.
    """
    
    # retrieve the hostname using in-built cli module
    host_name = cli.cli("show running-config | include hostname")
    FROM_ADDR = 'xxxx@cisco.com'
    TO_ADDR = 'xxxx@gmail.com'
    
    # create the message
    msg = MIMEMultipart()
    msg['From'] = FROM_ADDR
    msg['To'] = TO_ADDR
    msg['Subject'] = "%s - %s" % (subject, host_name)
    text = "This is an automated e mail message:\n===========================\nAn on-Box Python script running on a Cisco Polaris guestshell device and detected that the %s %s \n===========================\n\n\n===========================\n\n" % (subject, host_name)
    msg.attach(MIMEText(text, 'plain'))
    
    # connect to server and send
    server = smtplib.SMTP('outbound.your_company_name.com', 25)
    server.sendmail(FROM_ADDR, TO_ADDR, msg.as_string())
    server.quit() 
開發者ID:CiscoDevNet,項目名稱:python_code_samples_network,代碼行數:25,代碼來源:port_flap_email_alert.py

示例12: sendEmail

# 需要導入模塊: from email import MIMEText [as 別名]
# 或者: from email.MIMEText import MIMEText [as 別名]
def sendEmail(SUBJECT, BODY, TO, FROM, SENDER, PASSWORD, SMTP_SERVER):
    """Sends an HTML email."""
    for body_charset in 'US-ASCII', 'ISO-8859-1', 'UTF-8':
        try:
            BODY.encode(body_charset)
        except UnicodeError:
            pass
        else:
            break
    msg = MIMEText(BODY.encode(body_charset), 'html', body_charset)
    msg['From'] = SENDER
    msg['To'] = TO
    msg['Subject'] = SUBJECT

    SMTP_PORT = 587
    session = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
    session.starttls()
    session.login(FROM, PASSWORD)
    session.sendmail(SENDER, TO, msg.as_string())
    session.quit() 
開發者ID:jjwang,項目名稱:laibot-client,代碼行數:22,代碼來源:app_utils.py

示例13: send_expire_email

# 需要導入模塊: from email import MIMEText [as 別名]
# 或者: from email.MIMEText import MIMEText [as 別名]
def send_expire_email(domain, days, config_options):
    """
       Generate an e-mail to let someone know a domain is about to expire
    """
    debug("Generating an e-mail to %s for domain %s" %
         (config_options["smtpto"], domain))
    msg = MIMEMultipart()
    msg['From'] = config_options["smtpfrom"]
    msg['To'] = config_options["smtpto"]
    msg['Subject'] = "The DNS Domain %s is set to expire in %d days" % (domain, days)

    body = "Time to renew %s" % domain
    msg.attach(MIMEText(body, 'plain'))

    smtp_connection = smtplib.SMTP(config_options["smtpserver"],config_options["smtpport"])
    message = msg.as_string()
    smtp_connection.sendmail(config_options["smtpfrom"], config_options["smtpto"], message)
    smtp_connection.quit() 
開發者ID:Matty9191,項目名稱:dns-domain-expiration-checker,代碼行數:20,代碼來源:dns-domain-expiration-checker.py

示例14: send_email_account

# 需要導入模塊: from email import MIMEText [as 別名]
# 或者: from email.MIMEText import MIMEText [as 別名]
def send_email_account(remote_server, remote_port, username, password, email_from, email_to, subject, body):
    if (remote_server == "smtp.gmail.com"):
        send_email_gmail(username, password, email_from, email_to, subject, body)
    else:
        # connect to remote mail server and forward message on
        server = smtplib.SMTP(remote_server, remote_port)

        msg = MIMEMultipart()
        msg['From'] = email_from
        msg['To'] = email_to
        msg['Subject'] = subject
        msg.attach(MIMEText(body, 'plain'))

        smtp_sendmail_return = ""
        try:
            server.login(username, password)
            smtp_sendmail_return = server.sendmail(email_from, email_to, msg.as_string())
        except Exception, e:
            print 'SMTP Exception:\n' + str( e) + '\n' + str( smtp_sendmail_return)
        finally: 
開發者ID:tatanus,項目名稱:Python4Pentesters,代碼行數:22,代碼來源:massemailer_with_login.py

示例15: send_email_direct

# 需要導入模塊: from email import MIMEText [as 別名]
# 或者: from email.MIMEText import MIMEText [as 別名]
def send_email_direct(email_from, email_to, subject, body):
    # find the appropiate mail server
    domain = email_to.split('@')[1]
    remote_server = get_mx_record(domain)
    if (remote_server is None):
        print "No valid email server could be found for [%s]!" % (email_to)
        return

    # connect to remote mail server and forward message on
    server = smtplib.SMTP(remote_server, 25)

    msg = MIMEMultipart()
    msg['From'] = email_from
    msg['To'] = email_to
    msg['Subject'] = subject
    msg.attach(MIMEText(body, 'plain'))

    smtp_sendmail_return = ""
    try:
        smtp_sendmail_return = server.sendmail(email_from, email_to, msg.as_string())
    except Exception, e:
        print 'SMTP Exception:\n' + str( e) + '\n' + str( smtp_sendmail_return) 
開發者ID:tatanus,項目名稱:Python4Pentesters,代碼行數:24,代碼來源:massemailer_direct.py


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