예제 #1
0
    def test_message(self):
        text = 'This is some text: 高兴'
        html = '<h1>Heading</h1>\n<p>This is a paragraph: 高兴</p>'
        msg = message(body=text)
        self.eq(message(body=text), MIMEText(text.encode('utf-8'), 'plain', 'utf-8'))
        self.eq(message(html=html), MIMEText(html.encode('utf-8'), 'html', 'utf-8'))

        msg = MIMEMultipart('alternative')
        msg.attach(MIMEText(text.encode('utf-8'), 'plain', 'utf-8'))
        msg.attach(MIMEText(html.encode('utf-8'), 'html', 'utf-8'))
        self.eq(message(body=text, html=html), msg)
예제 #2
0
 def test_images(self):
     html = '高兴: <img src="cid:logo">'
     img = os.path.join(folder, 'small-image.jpg')
     msg = MIMEMultipart('related')
     msg.attach(MIMEText(html.encode('utf-8'), 'html', 'utf-8'))
     with open(img, 'rb') as handle:
         img_part = MIMEImage(handle.read())
         img_part.add_header('Content-ID', '<logo>')
         msg.attach(img_part)
     self.eq(message(html=html, images={'logo': img}), msg)
예제 #3
0
 def check_attachment(self, img):
     msg = message(body='text', attachments=[img])
     img_part = list(msg.walk())[-1]
     eq_(img_part.get_content_type(), 'image/jpeg')
     if 'filename' in img:
         eq_(img_part.get_filename(), os.path.basename(img['filename']))