本文整理汇总了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