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


Python image.MIMEImage方法代碼示例

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


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

示例1: test_send_smtp_inline_images

# 需要導入模塊: from email.mime import image [as 別名]
# 或者: from email.mime.image import MIMEImage [as 別名]
def test_send_smtp_inline_images(self, mock_send_mime):
        image = read_fixture("sample.png")
        utils.send_email_smtp(
            "to", "subject", "content", app.config, images=dict(blah=image)
        )
        assert mock_send_mime.called
        call_args = mock_send_mime.call_args[0]
        logger.debug(call_args)
        assert call_args[0] == app.config["SMTP_MAIL_FROM"]
        assert call_args[1] == ["to"]
        msg = call_args[2]
        assert msg["Subject"] == "subject"
        assert msg["From"] == app.config["SMTP_MAIL_FROM"]
        assert len(msg.get_payload()) == 2
        mimeapp = MIMEImage(image)
        assert msg.get_payload()[-1].get_payload() == mimeapp.get_payload() 
開發者ID:apache,項目名稱:incubator-superset,代碼行數:18,代碼來源:email_tests.py

示例2: attach_images

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

示例3: test_add_header

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



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

示例4: test__all__

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

示例5: test_add_header

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



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

示例6: test_add_header

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



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

示例7: generate_list_entry

# 需要導入模塊: from email.mime import image [as 別名]
# 或者: from email.mime.image import MIMEImage [as 別名]
def generate_list_entry(mime_images, alert, screenshots, filenames, url, count):
    result = '<hr><h3>' + alert + '</h3><h4>Alert generated on chart: <a href="' + url + '">' + url + '<a></h4>'
    if len(screenshots) > 0:
        for chart in screenshots:
            result += '<p><a href="' + chart + '"><img src="' + screenshots[chart] + '"/></a><br/><a href="'+screenshots[chart]+'">' + screenshots[chart] + '</a></p>'
    elif len(filenames) > 0:
        for chart in filenames:
            try:
                screenshot_id = str(count + 1)
                fp = open(filenames[chart], 'rb')
                mime_image = MIMEImage(fp.read())
                fp.close()
                mime_image.add_header('Content-ID', '<screenshot' + screenshot_id + '>')
                mime_images.append(mime_image)
                result += '<p><a href="' + chart + '"><img src="cid:screenshot' + screenshot_id + '"/></a><br/>' + filenames[chart] + '</p>'
            except Exception as send_mail_error:
                log.exception(send_mail_error)
                result += '<p><a href="' + url + '">Error embedding screenshot: ' + filenames[chart] + '</a><br/>' + filenames[chart] + '</p>'
    return result 
開發者ID:timelyart,項目名稱:Kairos,代碼行數:21,代碼來源:mail.py

示例8: get_attachments

# 需要導入模塊: from email.mime import image [as 別名]
# 或者: from email.mime.image import MIMEImage [as 別名]
def get_attachments(self):
        attachments = super().get_attachments()
        filename = (
            finders.find('images/email_logo.png')
            or finders.find('images/email_logo.svg')
        )
        if filename:
            if filename.endswith('.png'):
                imagetype = 'png'
            else:
                imagetype = 'svg+xml'

            with open(filename, 'rb') as f:
                logo = MIMEImage(f.read(), imagetype)

            logo.add_header('Content-ID', '<{}>'.format('logo'))
            return attachments + [logo]
        return attachments 
開發者ID:liqd,項目名稱:adhocracy4,代碼行數:20,代碼來源:mixins.py

示例9: _build_html_msg

# 需要導入模塊: from email.mime import image [as 別名]
# 或者: from email.mime.image import MIMEImage [as 別名]
def _build_html_msg(text, html, images):
    """Build Multipart message with in-line images and rich HTML (UTF-8)."""
    _LOGGER.debug("Building HTML rich email")
    msg = MIMEMultipart('related')
    alternative = MIMEMultipart('alternative')
    alternative.attach(MIMEText(text, _charset='utf-8'))
    alternative.attach(MIMEText(html, ATTR_HTML, _charset='utf-8'))
    msg.attach(alternative)

    for atch_num, atch_name in enumerate(images):
        name = os.path.basename(atch_name)
        try:
            with open(atch_name, 'rb') as attachment_file:
                attachment = MIMEImage(attachment_file.read(), filename=name)
            msg.attach(attachment)
            attachment.add_header('Content-ID', '<{}>'.format(name))
        except FileNotFoundError:
            _LOGGER.warning("Attachment %s [#%s] not found. Skipping",
                            atch_name, atch_num)
    return msg 
開發者ID:Teagan42,項目名稱:HomeAssistantConfig,代碼行數:22,代碼來源:notify.py

示例10: test_add_header

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



# Test the basic MIMEImage class 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:25,代碼來源:test_email_renamed.py

示例11: add_attachment

# 需要導入模塊: from email.mime import image [as 別名]
# 或者: from email.mime.image import MIMEImage [as 別名]
def add_attachment(self,filepath,filename=None):
        if filename == None:
            filename=os.path.basename(filepath)

        with open(filepath,'rb') as f:
            file=f.read()

        ctype, encoding = mimetypes.guess_type(filepath)
        if ctype is None or encoding is not None:ctype = "application/octet-stream"
        maintype, subtype = ctype.split('/', 1)

        if maintype == "text":
            with open(filepath) as f:file=f.read()
            attachment = MIMEText(file, _subtype=subtype)
        elif maintype == "image":
            with open(filepath,'rb') as f:file=f.read()
            attachment = MIMEImage(file, _subtype=subtype)
        elif maintype == "audio":
                with open(filepath,'rb') as f:file=f.read()
                attachment = MIMEAudio(file, _subtype=subtype)
        else:
                with open(filepath,'rb') as f:file=f.read()
                attachment = MIMEBase(maintype,subtype)
                attachment.set_payload(file)
                attachment.add_header('Content-Disposition', 'attachment', filename=filename)
                encoders.encode_base64(attachment)

        attachment.add_header('Content-Disposition', 'attachment', filename=filename)
        attachment.add_header('Content-ID',str(self.attachment_num))
        self.attachment_num+=1

        self.attachment_list.append(attachment) 
開發者ID:Aliencn,項目名稱:Smail,代碼行數:34,代碼來源:Smail.py

示例12: get_attachments

# 需要導入模塊: from email.mime import image [as 別名]
# 或者: from email.mime.image import MIMEImage [as 別名]
def get_attachments(self):
        # this returns two attachments, one a text file, the other an inline attachment that can be referred to in a
        # template using cid: notation
        fp = open('tests/python.jpeg', 'rb')
        img = MIMEImage(fp.read())
        img.add_header('Content-ID', '<{}>'.format('python.jpg'))

        raw_data = 'Some Report Data'

        return [
            ('Report.txt', raw_data, 'text/plain'),
            img,
        ] 
開發者ID:worthwhile,項目名稱:django-herald,代碼行數:15,代碼來源:notifications.py

示例13: setUp

# 需要導入模塊: from email.mime import image [as 別名]
# 或者: from email.mime.image import MIMEImage [as 別名]
def setUp(self):
        fp = openfile('PyBanner048.gif')
        try:
            self._imgdata = fp.read()
        finally:
            fp.close()
        self._im = MIMEImage(self._imgdata) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:test_email_renamed.py

示例14: test_checkSetMinor

# 需要導入模塊: from email.mime import image [as 別名]
# 或者: from email.mime.image import MIMEImage [as 別名]
def test_checkSetMinor(self):
        im = MIMEImage(self._imgdata, 'fish')
        self.assertEqual(im.get_content_type(), 'image/fish') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:5,代碼來源:test_email_renamed.py

示例15: send_email

# 需要導入模塊: from email.mime import image [as 別名]
# 或者: from email.mime.image import MIMEImage [as 別名]
def send_email(strTo):
    strFrom = config.fromaddr
    msgRoot = MIMEMultipart('related')
    msgRoot['Subject'] = 'Thanks for your ticket'
    msgRoot['From'] = strFrom
    msgRoot['To'] = strTo

    #Add text message to the MIME object
    msgRoot.preamble = 'This is a multi-part message in MIME format.'
    msgAlternative = MIMEMultipart('alternative')
    msgRoot.attach(msgAlternative)
    msgText = MIMEText('This is the alternative plain text message.')
    msgAlternative.attach(msgText)
    msgText = MIMEText('Hi there, <br><br>Thanks for your query with us today.'
                       ' You can look at our <a href="https://google.com">FAQs</a>'
                       ' and we shall get back to you soon.<br><br>'
                       'Thanks,<br>Support Team<br><br><img src="cid:image1">', 'html')
    msgAlternative.attach(msgText)

    #Add logo image to the auto response
    fp = open('google.png', 'rb')
    msgImage = MIMEImage(fp.read())
    fp.close()
    msgImage.add_header('Content-ID', '<image1>')
    msgRoot.attach(msgImage)

    #Start SMTO Server and respond to the customer
    import smtplib
    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.starttls()
    server.login(config.fromaddr, config.password)
    server.sendmail(config.fromaddr, config.toaddr, msgRoot.as_string())
    server.quit()

#Infinite loop to read the inbox for new emails 
#every 60 seconds (1 minute) 
開發者ID:PacktPublishing,項目名稱:Automate-it,代碼行數:38,代碼來源:support.py


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