当前位置: 首页>>代码示例>>Python>>正文


Python MIMEImage.set_payload方法代码示例

本文整理汇总了Python中email.MIMEImage.MIMEImage.set_payload方法的典型用法代码示例。如果您正苦于以下问题:Python MIMEImage.set_payload方法的具体用法?Python MIMEImage.set_payload怎么用?Python MIMEImage.set_payload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在email.MIMEImage.MIMEImage的用法示例。


在下文中一共展示了MIMEImage.set_payload方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build

# 需要导入模块: from email.MIMEImage import MIMEImage [as 别名]
# 或者: from email.MIMEImage.MIMEImage import set_payload [as 别名]
	def build(self, meAddress, ToAddressList, subject, message, AttachPathList):
		dateStr = time.strftime("%a, %d %b %Y %H:%M:%S +0000",time.localtime())
		self.__MeAddress = meAddress
		self.__ToAddressList = ToAddressList
		self.__Subject = subject
		self.__Message = message
		self.__oMIME = MIMEMultipart()
		self.__oMIME['Date'] = dateStr
		messageIdStr = '<' + str(int(time.time())) + '-' + str(random.randint(0,9999999)) + '@buscaplus.com' + '>'
		self.__oMIME['Message-ID'] = messageIdStr
		self.__oMIME['Subject'] = subject
		self.__oMIME['From'] = meAddress
		self.__oMIME['To'] = string.join(ToAddressList, ',')
		# Add Text
		oPart = MIMEText(message, 'plain', self.__CharSet)
		self.__oMIME.attach(oPart)
		# Add Attachments
		i = 0
		while i != len(AttachPathList):
			attachPath = AttachPathList[i]
			PathList = attachPath.split('/')
			fileName = PathList[len(PathList)-1]
			attachType, attachEncoding = mimetypes.guess_type(attachPath)
			mainType, subType = attachType.split('/')
			if mainType == 'image':
				fp = open(attachPath, 'rb')
				msg = MIMEImage(fp.read(), _subtype=subType)
				fp.close()
			elif mainType == 'audio':
				fp = open(attachPath, 'rb')
				msg = MIMEAudio(fp.read(), _subtype=subType)
				fp.close()
			else:
				fp = open(attachPath, 'rb')
				msg = MIMEBase(mainType, subType)
				msg.set_payload(fp.read())
				fp.close()
				# Encode the payload using Base64
				Encoders.encode_base64(msg)
			msg.add_header('Content-Disposition', 'attachment', filename=fileName)
			self.__oMIME.attach(msg)
			i = i + 1
开发者ID:Ximpia,项目名称:ximpia,代码行数:44,代码来源:ut_email.py


注:本文中的email.MIMEImage.MIMEImage.set_payload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。