def test_attachment_unicode_filename(self): msg = Message(fromaddr='*****@*****.**', to='*****@*****.**') # Chinese filename :) msg.attach_attachment(u'我的测试文档.txt', 'text/plain', 'this is test') self.assert_in('filename*="utf-8\'\'%E6%88%91%E7%9A%84%E6%B5%8B%E8%AF' '%95%E6%96%87%E6%A1%A3.txt"', str(msg))
def test_attachment_unicode_filename(self): msg = Message(fromaddr='*****@*****.**', to='*****@*****.**') # Chinese filename :) msg.attach_attachment(u'我的测试文档.txt', 'text/plain', 'this is test') self.assert_in( 'UTF8\'\'%E6%88%91%E7%9A%84%E6%B5%8B%E8%AF' '%95%E6%96%87%E6%A1%A3.txt', str(msg))
def test_plain_text_with_attachments(self): msg = Message(fromaddr='*****@*****.**', to='*****@*****.**', subject='hello', body='hello world') msg.attach_attachment(content_type='text/plain', data=b'this is test') self.assert_in('Content-Type: multipart/mixed', str(msg))
def test_attachment_ascii_filename(self): msg = Message(fromaddr='*****@*****.**', to='*****@*****.**') msg.attach_attachment('my test doc.txt', 'text/plain', 'this is test') self.assert_in('Content-Disposition: attachment;filename=' 'my test doc.txt', str(msg))
def test_attach_attachment(self): msg = Message() msg.attach_attachment('test.txt', 'text/plain', 'this is test') self.assert_equal(msg.attachments[0].filename, 'test.txt') self.assert_equal(msg.attachments[0].content_type, 'text/plain') self.assert_equal(msg.attachments[0].data, 'this is test')
username=SMTP_USER, password=SMTP_PASS, fromaddr=SMTP_ADDRESS) msg01 = Message("Hello01", to="*****@*****.**", body="hello world") msg02 = Message("Hello02", to="*****@*****.**") msg02.fromaddr = ('no-reply', '*****@*****.**') msg02.body = "hello world!" msg03 = Message("Hello03", to="*****@*****.**") msg03.fromaddr = (u'请勿回复', '*****@*****.**') msg03.body = u"你好世界" # Chinese :) msg03.html = u"<b>你好世界</b>" msg04 = Message("Hello04", body="Hello world 04") msg04.to = "*****@*****.**" msg04.cc = ["*****@*****.**", "cc02@example"] msg04.bcc = ["*****@*****.**"] msg05 = Message("Hello05", to="*****@*****.**", body="Hello world 05") with open("../docs/_static/sender.png") as f: msg05.attach_attachment("sender.png", "image/png", f.read()) msg06 = Message("Hello06", to="*****@*****.**", body="Hello world 06") with open("test.txt") as f: attachment = Attachment("test.txt", "text/plain", f.read()) msg06.attach(attachment) mail.send([msg01, msg02, msg03, msg04, msg05, msg06])
def test_attachment_ascii_filename(self): msg = Message(fromaddr='*****@*****.**', to='*****@*****.**') msg.attach_attachment('my test doc.txt', 'text/plain', b'this is test') self.assert_in( 'Content-Disposition: attachment; filename=' '"my test doc.txt"', str(msg))
msg02 = Message("Hello02", to="*****@*****.**") msg02.fromaddr = ('no-reply', '*****@*****.**') msg02.body = "hello world!" msg03 = Message("Hello03", to="*****@*****.**") msg03.fromaddr = (u'请勿回复', '*****@*****.**') msg03.body = u"你好世界" # Chinese :) msg03.html = u"<b>你好世界</b>" msg04 = Message("Hello04", body="Hello world 04") msg04.to = "*****@*****.**" msg04.cc = ["*****@*****.**", "cc02@example"] msg04.bcc = ["*****@*****.**"] msg05 = Message("Hello05", to="*****@*****.**", body="Hello world 05") with open("../docs/_static/sender.png") as f: msg05.attach_attachment("sender.png", "image/png", f.read()) msg06 = Message("Hello06", to="*****@*****.**", body="Hello world 06") with open("test.txt") as f: attachment = Attachment("test.txt", "text/plain", f.read()) msg06.attach(attachment) mail.send([msg01, msg02, msg03, msg04, msg05, msg06])