email_obj.set_payload(email_data) 在这里,`email_data`是包含了电子邮件原始数据的字符串。 一旦我们有了电子邮件对象,我们可以使用`get_payload`函数来检索有效负载。下面是一个例子: python payload = email_obj.get_payload() 这将返回一个包含电子邮件有效负载的对象。根据电子邮件
`get_payload`函数是Python中`email`模块中的一个方法,可以用于获取邮件的主要内容。 `get_payload`函数的原型如下: def get_payload(self, i=None, decode=False) 在这个函数中,`i`参数表示要获取的邮件部分的索引,默认为`None`,表示获取所有的邮件部分。`decode`参数表示是否对获取的邮件进行解码,默认为`...
最后,我们获取邮件的正文内容。这里我们使用get_payload()方法。 ifmsg.is_multipart():forpartinmsg.walk():c_type=part.get_content_type()c_dispo=str(part.get('Content-Disposition'))ifc_type=='text/plain'and'attachment'notinc_dispo:mail_content=part.get_payload(decode=True).decode('utf-8')p...
get_payload(decode=True) h = email.Header.Header(fileName) dh = email.Header.decode_header(h) fname = dh[0][0] encodeStr = dh[0][1] if encodeStr != None: fname = fname.decode(encodeStr, mycode) #end if fEx = open("%s"%(fname), 'wb') fEx.write(data) fEx.close() ...
me@,对方的电子邮件地址是friend@sina.com(注意地址都是虚构的哈),现在我们用Outlook或者Foxmail之类的软件写好邮件,填上对方的Email地址,点“发送”,电子邮件就发出去了。这些电子邮件软件被称为MUA:Mail User Agent——邮件用户代理。 Email从MUA发出去,不是直接到达对方电脑,而是发到MTA:Mail Transfer Agent——...
message_from_string(raw_email) for part in msg.walk(): if part.get_content_maintype() == 'multipart': continue if part.get('Content-Disposition') is None: continue filename = part.get_filename() if bool(filename): with open(filename, 'wb') as f: f.write(part.get_payload(decode...
email 分为头部(header)和主体(body 或 payload)。 如果EmailMessage 对象的 content type 是单一的(text/plain、image/png、application/zip 等),使用 get_content 方法获取 playload; 如果EmailMessage 对象的 content type 是 multiparts(multiparts/mixed 等),此时 payload 是由多个 parts 组成的,每个 parts 都...
get_payload(decode=True).decode(charset) except AttributeError: print('type error') except LookupError: print("unknown encoding: utf-8") if email_content_type =='': continue #如果内容为空,也跳过 print(email_content_type + ' --- ' + content) # --- 收取和发送邮件两个函数 --- def s...
mailobject = unicode(mail.get_payload(decode=True),charset) elif charset == None: mailobject = mail.get_payload(decode=True) else: mailobject = mail.get_payload(decode=charset).decode(charset) except: print 'BLANK' elif types == 'text/base64': ...
message = email.message_from_string('\n'.join(lines)) 8. 已经有了邮件所有信息,可以通过Message.get_payload()取出邮件正文了。 但是,get_payload()函数并不一定返回邮件正文。以下是官方说明: Return the current payload, which will be a list of Message objects when is_multipart() is True, or a...