本文整理匯總了Python中email.MIMEImage.MIMEImage方法的典型用法代碼示例。如果您正苦於以下問題:Python MIMEImage.MIMEImage方法的具體用法?Python MIMEImage.MIMEImage怎麽用?Python MIMEImage.MIMEImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類email.MIMEImage
的用法示例。
在下文中一共展示了MIMEImage.MIMEImage方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_add_header
# 需要導入模塊: from email import MIMEImage [as 別名]
# 或者: from email.MIMEImage 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
示例2: test__all__
# 需要導入模塊: from email import MIMEImage [as 別名]
# 或者: from email.MIMEImage import MIMEImage [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',
])
示例3: test_add_header
# 需要導入模塊: from email import MIMEImage [as 別名]
# 或者: from email.MIMEImage 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
示例4: test_add_header
# 需要導入模塊: from email import MIMEImage [as 別名]
# 或者: from email.MIMEImage 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
示例5: setUp
# 需要導入模塊: from email import MIMEImage [as 別名]
# 或者: from email.MIMEImage import MIMEImage [as 別名]
def setUp(self):
fp = openfile('PyBanner048.gif')
try:
self._imgdata = fp.read()
finally:
fp.close()
self._im = MIMEImage(self._imgdata)
示例6: test_checkSetMinor
# 需要導入模塊: from email import MIMEImage [as 別名]
# 或者: from email.MIMEImage import MIMEImage [as 別名]
def test_checkSetMinor(self):
im = MIMEImage(self._imgdata, 'fish')
self.assertEqual(im.get_content_type(), 'image/fish')
示例7: process
# 需要導入模塊: from email import MIMEImage [as 別名]
# 或者: from email.MIMEImage import MIMEImage [as 別名]
def process(options, args):
config = get_config(options)
# Write the email
msg = MIMEMultipart()
msg['From'] = config['fromaddr']
msg['To'] = config['toaddrs']
msg['Subject'] = options.subject
body = options.body
msg.attach(MIMEText(body, 'plain'))
# Attach image
if options.image_file:
try:
filename = open(options.image_file, "rb")
attach_image = MIMEImage(filename.read())
attach_image.add_header('Content-Disposition',
'attachment; filename = %s'%options.image_file)
msg.attach(attach_image)
filename.close()
except:
msg.attach(MIMEText('Image attachment error', 'plain'))
# Converting email to text
text = msg.as_string()
# The actual mail send
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.ehlo()
server.login(config['username'],config['password'])
server.sendmail(config['fromaddr'], config['toaddrs'], text)
server.quit()
示例8: test_mime
# 需要導入模塊: from email import MIMEImage [as 別名]
# 或者: from email.MIMEImage import MIMEImage [as 別名]
def test_mime(self):
msg = EmailMultiAlternatives(
subject="Hello, World!",
body=" ",
from_email="Sam Smith <sam.smith@example.com>",
to=["John Doe <john.doe@example.com>", "jane.doe@example.com"],
)
content = '<body><img src="cid:linux_penguin" /></body>'
msg.attach_alternative(content, "text/html")
with open("test/linux-penguin.png", "rb") as f:
img = MIMEImage(f.read())
img.add_header("Content-ID", "<linux_penguin>")
msg.attach(img)
result = self.backend._build_sg_mail(msg)
self.assertEqual(len(result["content"]), 2)
self.assertDictEqual(result["content"][0], {"type": "text/plain", "value": " "})
self.assertDictEqual(result["content"][1], {"type": "text/html", "value": content})
self.assertEqual(len(result["attachments"]), 1)
self.assertEqual(result["attachments"][0]["content_id"], "linux_penguin")
with open("test/linux-penguin.png", "rb") as f:
if sys.version_info >= (3.0, 0.0, ):
self.assertEqual(bytearray(result["attachments"][0]["content"], "utf-8"), base64.b64encode(f.read()))
else:
self.assertEqual(result["attachments"][0]["content"], base64.b64encode(f.read()))
self.assertEqual(result["attachments"][0]["type"], "image/png")