概述
defsend_mail_multi(headers,text,msgHtml="",orig=None):"""
"""msg=MIMEMultipart('mixed')# Create message container - the correct MIME type is multipart/alternative.body=MIMEMultipart('alternative')fork,vinheaders.items():ifisinstance(v,list):v=', '.join(v)msg.add_header(k,v)# Attach parts into message container.# According to RFC 2046, the last part of a multipart message, in this case# the HTML message, is best and preferred.iforigisnotNone:text,msgHtml2=append_orig_text(text,msgHtml,orig,False)# Fix subjectmsg["Subject"]="RE: "+orig["Subject"].replace("Re: ","").replace("RE: ","")msg['In-Reply-To']=orig["Message-ID"]msg['References']=orig["Message-ID"]#+orig["References"].strip()msg['Thread-Topic']=orig["Thread-Topic"]msg['Thread-Index']=orig["Thread-Index"]body.attach(MIMEText(text,'plain'))ifmsgHtml!="":body.attach(MIMEText(msgHtml2,'html'))msg.attach(body)send_it(msg)defappend_orig_text(text,html,orig,google=False):"""
Append each part of the orig message into 2 new variables
(html and text) and return them. Also, remove any
attachments. If google=True then the reply will be prefixed
with ">". The last is not tested with html messages...
"""newhtml=""newtext=""forpartinorig.walk():if(part.get('Content-Disposition')andpart.get('Content-Disposition').startswith("attachment")):part.set_type("text/plain")part.set_payload("Attachment removed: %s (%s, %d bytes)"%(part.get_filename(),part.get_content_type(),len(part.get_payload(decode=True))))delpart["Content-Disposition"]delpart["Content-Transfer-Encoding"]ifpart.get_content_type().startswith("text/plain"):newtext+="n"newtext+=part.get_payload(decode=False)ifgoogle:newtext=newtext.replace("n","n> ")elifpart.get_content_type().startswith("text/html"):newhtml+="n"newhtml+=part.get_payload(decode=True).decode("utf-8")ifgoogle:newhtml=newhtml.replace("n","n> ")ifnewhtml=="":newhtml=newtext.replace('n','
')return(text+'nn'+newtext,html+'
'+newhtml)
最后
以上就是义气发夹为你收集整理的python回复邮件_使用python 3.4回复电子邮件的全部内容,希望文章能够帮你解决python回复邮件_使用python 3.4回复电子邮件所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复