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


Python multipart.MIMEMultipart方法代碼示例

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


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

示例1: attach_images

# 需要導入模塊: from email.mime import multipart [as 別名]
# 或者: from email.mime.multipart import MIMEMultipart [as 別名]
def attach_images(*fns):
    email = MIMEMultipart()
    for fn in fns:
        if not img_patt.search(fn.split('.')[-1]):
            # Following is kinda like throwing an exception, but better.
            print("%s doesn't seem to be an image file. Skipping." % fn)
            continue
        if url_patt.match(fn):
            data = requests.get(fn).content
        else:
            with open(fn, 'rb') as f:
                data = f.read()
        img = MIMEImage(data, name=fn)
        img.add_header('Content-Disposition', 'attachment; filename="%s"' % fn)
        email.attach(img)
    return email 
開發者ID:wdxtub,項目名稱:deep-learning-note,代碼行數:18,代碼來源:4_generate_email.py

示例2: send_email

# 需要導入模塊: from email.mime import multipart [as 別名]
# 或者: from email.mime.multipart import MIMEMultipart [as 別名]
def send_email(contact):
    recipient = contact[recipient_column]
    email_text = body_value if use_body_value else contact.get(body_column, "")
    email_subject = subject_value if use_subject_value else contact.get(subject_column, "")
    sender = sender_value if use_sender_value else contact.get(sender_column, "")
    
    msg = MIMEMultipart()

    msg["From"] = sender
    msg["To"] = recipient
    msg["Subject"]=  email_subject

    # Leave some space for proper displaying of the attachment
    msg.attach(MIMEText(email_text + '\n\n', 'plain', body_encoding))
    for a in mime_parts:
        msg.attach(a)

    s.sendmail(sender, [recipient], msg.as_string()) 
開發者ID:dataiku,項目名稱:dataiku-contrib,代碼行數:20,代碼來源:recipe.py

示例3: sendfailmail

# 需要導入模塊: from email.mime import multipart [as 別名]
# 或者: from email.mime.multipart import MIMEMultipart [as 別名]
def sendfailmail():
    try:
        SUBJECT = 'QQ點讚機下線提醒'
        TO = [sendtomail]
        msg = MIMEMultipart('alternative')
        msg['Subject'] = Header(SUBJECT, 'utf-8')
        msg['From'] = mailsig+'<'+mailuser+'>'
        msg['To'] = ', '.join(TO)
        part = MIMEText("Fatal error occured. Please go to the website and login again!", 'plain', 'utf-8')
        msg.attach(part)
        server = smtplib.SMTP(mailserver, 25)
        server.login(mailuser, mailpass)
        server.login(mailuser, mailpass)
        server.sendmail(mailuser, TO, msg.as_string())
        server.quit()
        return True
    except Exception , e:
        logging.error("發送程序錯誤郵件失敗:"+str(e))
        return False 
開發者ID:zeruniverse,項目名稱:QBotWebWrap,代碼行數:21,代碼來源:qqbot.py

示例4: sendfailmail

# 需要導入模塊: from email.mime import multipart [as 別名]
# 或者: from email.mime.multipart import MIMEMultipart [as 別名]
def sendfailmail():
    global QQUserName, MyUIN
    try:
        SUBJECT = 'QQ掛機下線提醒: '+str(QQUserName)+'[QQ號:'+str(MyUIN)+']'
        TO = [sendtomail]
        msg = MIMEMultipart('alternative')
        msg['Subject'] = Header(SUBJECT, 'utf-8')
        msg['From'] = mailsig+'<'+mailuser+'>'
        msg['To'] = ', '.join(TO)
        part = MIMEText("Fatal error occured. Please restart the program and login again!", 'plain', 'utf-8')
        msg.attach(part)
        server = smtplib.SMTP(mailserver, 25)
        server.login(mailuser, mailpass)
        server.login(mailuser, mailpass)
        server.sendmail(mailuser, TO, msg.as_string())
        server.quit()
        return True
    except Exception , e:
        logging.error("發送程序錯誤郵件失敗:"+str(e))
        return False 
開發者ID:zeruniverse,項目名稱:QBotWebWrap,代碼行數:22,代碼來源:qqbot.py

示例5: smtpmail

# 需要導入模塊: from email.mime import multipart [as 別名]
# 或者: from email.mime.multipart import MIMEMultipart [as 別名]
def smtpmail(self,subinfo):
        try:
            SUBJECT = '來自 '+subinfo+'的留言'
            TO = [sendtomail]
            msg = MIMEMultipart('alternative')
            msg['Subject'] = Header(SUBJECT, 'utf-8')
            msg['From'] = mailsig+'<'+mailuser+'>'
            msg['To'] = ', '.join(TO)
            part = MIMEText(self.content, 'plain', 'utf-8')
            msg.attach(part)        
            server = smtplib.SMTP(mailserver, 25)
            server.login(mailuser, mailpass)
            server.login(mailuser, mailpass)
            server.sendmail(mailuser, TO, msg.as_string())
            server.quit()
            return True
        except Exception, e:
            logging.error("error sending msg:"+str(e))
            return False 
開發者ID:zeruniverse,項目名稱:QBotWebWrap,代碼行數:21,代碼來源:qqbot.py

示例6: sendfailmail

# 需要導入模塊: from email.mime import multipart [as 別名]
# 或者: from email.mime.multipart import MIMEMultipart [as 別名]
def sendfailmail():
    try:
        SUBJECT = 'QQ小黃雞下線提醒'
        TO = [sendtomail]
        msg = MIMEMultipart('alternative')
        msg['Subject'] = Header(SUBJECT, 'utf-8')
        msg['From'] = mailsig+'<'+mailuser+'>'
        msg['To'] = ', '.join(TO)
        part = MIMEText("Fatal error occured. Please go to the website and login again!", 'plain', 'utf-8')
        msg.attach(part)
        server = smtplib.SMTP(mailserver, 25)
        server.login(mailuser, mailpass)
        server.login(mailuser, mailpass)
        server.sendmail(mailuser, TO, msg.as_string())
        server.quit()
        return True
    except Exception , e:
        logging.error("發送程序錯誤郵件失敗:"+str(e))
        return False 
開發者ID:zeruniverse,項目名稱:QBotWebWrap,代碼行數:21,代碼來源:qqbot.py

示例7: sendEmail

# 需要導入模塊: from email.mime import multipart [as 別名]
# 或者: from email.mime.multipart import MIMEMultipart [as 別名]
def sendEmail(subject, body, credentials):    
    self = credentials[0]
    password = credentials[1]    
    fromAddr = credentials[2]
    toAddr = credentials[3]   
    msg = MIMEMultipart()
    msg['From'] = fromAddr
    msg['To'] = toAddr
    msg['Subject'] = subject   
    msgText = MIMEText(body, 'html', 'UTF-8')
    msg.attach(msgText)
    server = SMTP('smtp.gmail.com', 587)
    server.starttls()
    server.login(self, password)
    text = msg.as_string()
    server.sendmail(fromAddr, toAddr, text)
    server.quit()

# --- Scraping Methods --------------------------------------------------------- 
開發者ID:anfederico,項目名稱:Stockeye,代碼行數:21,代碼來源:watch.py

示例8: test_generate_email

# 需要導入模塊: from email.mime import multipart [as 別名]
# 或者: from email.mime.multipart import MIMEMultipart [as 別名]
def test_generate_email(get_email, mocker):
    """
    GIVEN a valid Email object
    WHEN Email.generate_email() is called
    THEN assert the email structure is created
    """
    header_mock = mocker.patch.object(Email, '_add_header')
    body_mock = mocker.patch.object(Email, '_add_body')
    attach_mock = mocker.patch.object(Email, '_add_attachments')
    e = get_email
    e._generate_email()
    assert isinstance(e.message, MIMEMultipart)
    assert header_mock.call_count == 1
    assert body_mock.call_count == 1
    assert attach_mock.call_count == 1


##############################################################################
# TESTS: Email._add_header
############################################################################## 
開發者ID:trp07,項目名稱:messages,代碼行數:22,代碼來源:test_email.py

示例9: test_add_body

# 需要導入模塊: from email.mime import multipart [as 別名]
# 或者: from email.mime.multipart import MIMEMultipart [as 別名]
def test_add_body(get_email, mocker):
    """
    GIVEN a valid Email object, where Email.generate_email() has been called
    WHEN Email.add_body() is called
    THEN assert body_text is attached
    """
    attach_mock = mocker.patch.object(Email, '_add_attachments')
    header_mock = mocker.patch.object(Email, '_add_header')
    mime_attach_mock = mocker.patch.object(MIMEMultipart, 'attach')
    e = get_email
    e._generate_email()
    assert mime_attach_mock.call_count == 1


##############################################################################
# TESTS: Email._add_attachments
############################################################################## 
開發者ID:trp07,項目名稱:messages,代碼行數:19,代碼來源:test_email.py

示例10: test_add_attachments_str_travis

# 需要導入模塊: from email.mime import multipart [as 別名]
# 或者: from email.mime.multipart import MIMEMultipart [as 別名]
def test_add_attachments_str_travis(get_email, mocker):
    """
    GIVEN a valid Email object, where Email.generate_email() has been called
         and Email.attachments is a str
    WHEN Email.add_attachments() is called
    THEN assert correct attachments are attached
    """
    header_mock = mocker.patch.object(Email, '_add_header')
    body_mock = mocker.patch.object(Email, '_add_body')
    mime_attach_mock = mocker.patch.object(MIMEMultipart, 'attach')
    e = get_email
    PATH = '/home/travis/build/trp07/messages/tests/data/'
    e.attachments = PATH + 'file1.txt'
    e._generate_email()
    assert mime_attach_mock.call_count == 1


##############################################################################
# TESTS: Email._get_session
############################################################################## 
開發者ID:trp07,項目名稱:messages,代碼行數:22,代碼來源:test_email.py

示例11: send_message

# 需要導入模塊: from email.mime import multipart [as 別名]
# 或者: from email.mime.multipart import MIMEMultipart [as 別名]
def send_message(self, to_user, title, body, **kwargs):
        if self.ssl:
            smtp_client = smtplib.SMTP_SSL()
        else:
            smtp_client = smtplib.SMTP()
        smtp_client.connect(zvt_env['smtp_host'], zvt_env['smtp_port'])
        smtp_client.login(zvt_env['email_username'], zvt_env['email_password'])
        msg = MIMEMultipart('alternative')
        msg['Subject'] = Header(title).encode()
        msg['From'] = "{} <{}>".format(Header('zvt').encode(), zvt_env['email_username'])
        if type(to_user) is list:
            msg['To'] = ", ".join(to_user)
        else:
            msg['To'] = to_user
        msg['Message-id'] = email.utils.make_msgid()
        msg['Date'] = email.utils.formatdate()

        plain_text = MIMEText(body, _subtype='plain', _charset='UTF-8')
        msg.attach(plain_text)

        try:
            smtp_client.sendmail(zvt_env['email_username'], to_user, msg.as_string())
        except Exception as e:
            self.logger.exception('send email failed', e) 
開發者ID:zvtvz,項目名稱:zvt,代碼行數:26,代碼來源:informer.py

示例12: testExtractAttachedKey

# 需要導入模塊: from email.mime import multipart [as 別名]
# 或者: from email.mime.multipart import MIMEMultipart [as 別名]
def testExtractAttachedKey(self):
        KEY = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n..."

        message = MIMEMultipart()
        message.add_header("from", ADDRESS_2)
        key = MIMEApplication("", "pgp-keys")
        key.set_payload(KEY)
        message.attach(key)
        self.fetcher._keymanager.put_raw_key = Mock(
            return_value=defer.succeed(None))

        def put_raw_key_called(_):
            self.fetcher._keymanager.put_raw_key.assert_called_once_with(
                KEY, address=ADDRESS_2)

        d = self._do_fetch(message.as_string())
        d.addCallback(put_raw_key_called)
        return d 
開發者ID:leapcode,項目名稱:bitmask-dev,代碼行數:20,代碼來源:test_incoming_mail.py

示例13: testExtractInvalidAttachedKey

# 需要導入模塊: from email.mime import multipart [as 別名]
# 或者: from email.mime.multipart import MIMEMultipart [as 別名]
def testExtractInvalidAttachedKey(self):
        KEY = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n..."

        message = MIMEMultipart()
        message.add_header("from", ADDRESS_2)
        key = MIMEApplication("", "pgp-keys")
        key.set_payload(KEY)
        message.attach(key)
        self.fetcher._keymanager.put_raw_key = Mock(
            return_value=defer.fail(KeyAddressMismatch()))

        def put_raw_key_called(_):
            self.fetcher._keymanager.put_raw_key.assert_called_once_with(
                KEY, address=ADDRESS_2)

        d = self._do_fetch(message.as_string())
        d.addCallback(put_raw_key_called)
        d.addErrback(log.err)
        return d 
開發者ID:leapcode,項目名稱:bitmask-dev,代碼行數:21,代碼來源:test_incoming_mail.py

示例14: testExtractAttachedKeyAndNotOpenPGPHeader

# 需要導入模塊: from email.mime import multipart [as 別名]
# 或者: from email.mime.multipart import MIMEMultipart [as 別名]
def testExtractAttachedKeyAndNotOpenPGPHeader(self):
        KEY = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n..."
        KEYURL = "https://leap.se/key.txt"
        OpenPGP = "id=12345678; url=\"%s\"; preference=signencrypt" % (KEYURL,)

        message = MIMEMultipart()
        message.add_header("from", ADDRESS_2)
        message.add_header("OpenPGP", OpenPGP)
        key = MIMEApplication("", "pgp-keys")
        key.set_payload(KEY)
        message.attach(key)

        self.fetcher._keymanager.put_raw_key = Mock(
            return_value=defer.succeed(None))
        self.fetcher._keymanager.fetch_key = Mock()

        def put_raw_key_called(_):
            self.fetcher._keymanager.put_raw_key.assert_called_once_with(
                KEY, address=ADDRESS_2)
            self.assertFalse(self.fetcher._keymanager.fetch_key.called)

        d = self._do_fetch(message.as_string())
        d.addCallback(put_raw_key_called)
        return d 
開發者ID:leapcode,項目名稱:bitmask-dev,代碼行數:26,代碼來源:test_incoming_mail.py

示例15: testExtractOpenPGPHeaderIfInvalidAttachedKey

# 需要導入模塊: from email.mime import multipart [as 別名]
# 或者: from email.mime.multipart import MIMEMultipart [as 別名]
def testExtractOpenPGPHeaderIfInvalidAttachedKey(self):
        KEY = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n..."
        KEYURL = "https://leap.se/key.txt"
        OpenPGP = "id=12345678; url=\"%s\"; preference=signencrypt" % (KEYURL,)

        message = MIMEMultipart()
        message.add_header("from", ADDRESS_2)
        message.add_header("OpenPGP", OpenPGP)
        key = MIMEApplication("", "pgp-keys")
        key.set_payload(KEY)
        message.attach(key)

        self.fetcher._keymanager.put_raw_key = Mock(
            return_value=defer.fail(KeyAddressMismatch()))
        self.fetcher._keymanager.fetch_key = Mock()

        def put_raw_key_called(_):
            self.fetcher._keymanager.put_raw_key.assert_called_once_with(
                KEY, address=ADDRESS_2)
            self.fetcher._keymanager.fetch_key.assert_called_once_with(
                ADDRESS_2, KEYURL)

        d = self._do_fetch(message.as_string())
        d.addCallback(put_raw_key_called)
        return d 
開發者ID:leapcode,項目名稱:bitmask-dev,代碼行數:27,代碼來源:test_incoming_mail.py


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