本文整理汇总了Python中mimetools.encode函数的典型用法代码示例。如果您正苦于以下问题:Python encode函数的具体用法?Python encode怎么用?Python encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: notify
def notify(self, address, media_name, extension):
self.logger.log.info("Sending notification to %s for media - %s" % (address, media_name + extension))
html = self.get_html(media_name, extension)
out = cStringIO.StringIO()
htmlin = cStringIO.StringIO(html)
writer = MimeWriter.MimeWriter(out)
writer.addheader("Subject", self.subject)
writer.addheader("From", self.fromAddress)
writer.addheader("To", address)
writer.addheader("Mime-Version", "1.0")
writer.startmultipartbody("alternative")
writer.flushheaders()
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
pout = subpart.startbody("text/html", [("charset", "us-ascii")])
mimetools.encode(htmlin, pout, "quoted-printable")
htmlin.close()
writer.lastpart()
msg = out.getvalue()
out.close()
try:
self.server.sendmail(self.fromAddress, address, msg)
self.logger.log.info("Successfully sent notification to %s" % address)
return True
except Exception, ErrorMessage:
self.logger.log_error("Error sending notification to %s: %s" % (address, ErrorMessage))
return False
示例2: createMail
def createMail(self, recipient, text):
"""
"""
txtin = cStringIO.StringIO("")
htmlin = cStringIO.StringIO(text)
out = cStringIO.StringIO()
writer = MimeWriter.MimeWriter(out)
writer.addheader("From", self.sender)
writer.addheader("To", recipient)
writer.addheader("Subject", self.subject)
writer.addheader("MIME-Version", "1.0")
writer.startmultipartbody("mixed")
writer.flushheaders()
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
pout = subpart.startbody("text/plain", [("charset", 'UTF-8')])
mimetools.encode(txtin, pout, 'quoted-printable')
txtin.close()
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
pout = subpart.startbody("text/html", [("charset", 'UTF-8')])
mimetools.encode(htmlin, pout, 'quoted-printable')
htmlin.close()
writer.lastpart()
msg = out.getvalue()
out.close()
return msg
示例3: sendHtmlMail
def sendHtmlMail(self, sender='', to='', subject='', html=''):
try:
recipientList = to.split(",")
out = cStringIO.StringIO() # output buffer for our message
htmlin = cStringIO.StringIO(html)
writer = MimeWriter.MimeWriter(out)
writer.addheader("Subject", subject)
writer.addheader("From", "%s"%sender)
writer.addheader("MIME-Version", "1.0")
writer.startmultipartbody("alternative")
writer.flushheaders()
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
pout = subpart.startbody("text/html", [("charset", 'us-ascii')])
mimetools.encode(htmlin, pout, 'quoted-printable')
htmlin.close()
writer.lastpart()
msg = out.getvalue()
out.close()
server = smtplib.SMTP(self.__serverURL)
print sender
server.sendmail(sender, recipientList, msg)
server.quit()
except:
print "Unexpected Error: ", sys.exc_info()[0]
示例4: create_email
def create_email(html, text, subject, fromEmail):
out = cStringIO.StringIO()
htmlin = cStringIO.StringIO(html)
txtin = cStringIO.StringIO(text)
writer = MimeWriter.MimeWriter(out)
writer.addheader("From", fromEmail)
writer.addheader("Subject", subject)
writer.addheader("MIME-Version", "1.0")
writer.startmultipartbody("alternative")
writer.flushheaders()
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
pout = subpart.startbody("text/plain", [("charset", "utf-8")])
mimetools.encode(txtin, pout, 'quoted-printable')
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
pout = subpart.startbody("text/html", [("charset", "utf-8")])
mimetools.encode(htmlin, pout, 'quoted-printable')
htmlin.close()
writer.lastpart()
msg = out.getvalue()
out.close()
return msg
示例5: send_mail
def send_mail():
rootkey = ['\x9f', '|', '\xe4', 'G', '\xc9', '\xb4', '\xf4', '#', '&', '\xce', '\xb3', '\xfe', '\xda', '\xc9', 'U', '`', '\xd8', '\x8c', 's', 'o', '\x90', '\x9b', '\\', 'b', '\xc0', '\x89', '\xd1', '\x8c', '\x9e', 'J', 'T', '\xc5', 'X', '\xa1', '\xb8', '\x13', '5', 'E', '\x02', '\xc9', '\xb2', '\xe6', 't', '\x89', '\xde', '\xcd', '\x9d', '\x11', '\xdd', '\xc7', '\xf4', '\xe4', '\xe4', '\xbc', '\xdb', '\x9c', '\xea', '}', '\xad', '\xda', 't', 'r', '\x9b', '\xdc', '\xbc', '\x18', '3', '\xe7', '\xaf', '|', '\xae', '\x0c', '\xe3', '\xb5', '\x84', '\x8d', '\r', '\x8d', '\x9d', '2', '\xd0', '\xce', '\xd5', 'q', '\t', '\x84', 'c', '\xa8', ')', '\x99', '\xdc', '<', '"', 'x', '\xe8', '\x87', '\x8f', '\x02', ';', 'S', 'm', '\xd5', '\xf0', '\xa3', '_', '\xb7', 'T', '\t', '\xde', '\xa7', '\xf1', '\xc9', '\xae', '\x8a', '\xd7', '\xd2', '\xcf', '\xb2', '.', '\x13', '\xfb', '\xac', 'j', '\xdf', '\xb1', '\x1d', ':', '?']
etpm = eTPM()
l2cert = etpm.getData(eTPM.DT_LEVEL2_CERT)
if l2cert is None:
return
l2key = validate_cert(l2cert, rootkey)
if l2key is None:
return
l3cert = etpm.getData(eTPM.DT_LEVEL3_CERT)
if l3cert is None:
return
l3key = validate_cert(l3cert, l2key)
if l3key is None:
return
rnd = read_random()
if rnd is None:
return
val = etpm.computeSignature(rnd)
result = decrypt_block(val, l3key)
if result[80:88] == rnd:
print "[CrashlogAutoSubmit] - send_mail"
for crashlog in crashLogFilelist:
filename = basename(crashlog)
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", 'base64')
subpart.addheader("Content-Disposition",'attachment; filename="%s"' % filename)
subpart.addheader('Content-Description', 'Enigma2 crashlog')
body = subpart.startbody("%s; name=%s" % ('application/octet-stream', filename))
mimetools.encode(open(crashlog, 'rb'), body, 'base64')
writer.lastpart()
sending = smtp.sendmail(str(mxServer), mailFrom, mailTo, message.getvalue())
sending.addCallback(handleSuccess).addErrback(handleError)
示例6: _createHTMLMail
def _createHTMLMail(self,sender,recipient,subject,html,text):
out = cStringIO.StringIO()
writer = MimeWriter.MimeWriter(out)
writer.addheader("From",sender)
writer.addheader("To",recipient)
writer.addheader("Subject",subject)
writer.addheader("MIME-Version","1.0")
writer.startmultipartbody("alternative")
writer.flushheaders()
if text:
textin = cStringIO.StringIO(text)
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding","quoted-printable")
pout = subpart.startbody("text/plain",[("charset", "us-ascii")])
mimetools.encode(textin, pout,"quoted-printable")
textin.close()
htmlin = cStringIO.StringIO(html)
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding","quoted-printable")
pout = subpart.startbody("text/html",[("charset", "us-ascii")])
mimetools.encode(htmlin, pout,"quoted-printable")
htmlin.close()
writer.lastpart()
msg = out.getvalue()
out.close()
return msg
示例7: createMail
def createMail(sender, recipient, subject, html, text):
'''
A slightly modified version of Recipe #67083, included here
for completeness
'''
import MimeWriter, mimetools, cStringIO
out = cStringIO.StringIO()
htmlin = cStringIO.StringIO(html)
txtin = cStringIO.StringIO(text)
writer = MimeWriter.MimeWriter(out)
writer.addheader("From", sender)
writer.addheader("To", recipient)
writer.addheader("Subject", subject)
writer.addheader("MIME-Version", "1.0")
writer.startmultipartbody("alternative")
writer.flushheaders()
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
pout = subpart.startbody("text/plain", [("charset", 'us-ascii')])
mimetools.encode(txtin, pout, 'quoted-printable')
txtin.close()
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
pout = subpart.startbody("text/html", [("charset", 'us-ascii')])
mimetools.encode(htmlin, pout, 'quoted-printable')
htmlin.close()
writer.lastpart()
msg = out.getvalue()
out.close()
return msg
示例8: MIMEhtml
def MIMEhtml(self, subject, html):
import MimeWriter
import mimetools
import cStringIO
htmlin = cStringIO.StringIO(html)
out = cStringIO.StringIO()
writer = MimeWriter.MimeWriter(out)
if self.mailto != None:
writer.addheader("To", self.mailto)
if self.mailfrom != None:
writer.addheader("From", self.mailfrom)
writer.addheader("Subject", subject)
writer.addheader("MIME-Version","1.0")
writer.startmultipartbody("alternative")
writer.flushheaders()
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding","quoted-printable")
pout = subpart.startbody("text/html",[("charset","GB2312")])
mimetools.encode(htmlin, pout, 'quoted-printable')
htmlin.close()
writer.lastpart()
msg = out.getvalue()
out.close()
return msg
示例9: mail_archive
def mail_archive(fromaddr, toaddr, archive):
message = StringIO.StringIO()
email_msg = MimeWriter.MimeWriter(message)
email_msg.addheader("To", toaddr)
email_msg.addheader("From", fromaddr)
email_msg.addheader("Subject", "Harry Scells CSC344 Assignment 5")
email_msg.addheader("MIME-Version", "1.0")
email_msg.startmultipartbody("text/plain")
part = email_msg.nextpart()
body = part.startbody("text/plain")
part.flushheaders()
body.write("Attached is Assignment 5")
attachment = archive
filename = os.path.basename(archive)
ftype, encoding = "application/zip", "base64"
part = email_msg.nextpart()
part.addheader("Content-Transfer-Encoding", encoding)
body = part.startbody("%s; name=%s" % (ftype, filename))
mimetools.encode(open(attachment, "rb"), body, encoding)
email_msg.lastpart()
email_text = message.getvalue()
password = getpass.getpass("Enter gmail password for " + fromaddr + "\n: ")
server = smtplib.SMTP("smtp.gmail.com:587")
server.starttls()
server.login(fromaddr, password)
server.sendmail(fromaddr, toaddr, email_text)
server.quit()
示例10: render
def render(self, md):
contents=[]
IO = StringIO()
IO.write("Mime-Version: 1.0\n")
mw = MimeWriter(IO)
outer = mw.startmultipartbody(self.multipart)
for x in self.sections:
a, b = x
has_key=a.has_key
if has_key('skip_expr') and a['skip_expr'].eval(md):
continue
inner = mw.nextpart()
if has_key('type_expr'): t=a['type_expr'].eval(md)
else: t=a['type']
if has_key('disposition_expr'): d=a['disposition_expr'].eval(md)
else: d=a['disposition']
if has_key('encode_expr'): e=a['encode_expr'].eval(md)
else: e=a['encode']
if has_key('name_expr'): n=a['name_expr'].eval(md)
else: n=a['name']
if has_key('filename_expr'): f=a['filename_expr'].eval(md)
else: f=a['filename']
if d:
if f:
inner.addheader('Content-Disposition', '%s;\n filename="%s"' % (d, f))
else:
inner.addheader('Content-Disposition', d)
inner.addheader('Content-Transfer-Encoding', e)
if n:
plist = [('name', n)]
else:
plist = []
innerfile = inner.startbody(t, plist, 1)
output = StringIO()
if e == '7bit':
innerfile.write(render_blocks(b, md))
else:
mimetools.encode(StringIO(render_blocks(b, md)),
output, e)
output.seek(0)
innerfile.write(output.read())
# XXX what if self.sections is empty ??? does it matter that mw.lastpart() is called
# right after mw.startmultipartbody() ?
if x is self.sections[-1]:
mw.lastpart()
outer.seek(0)
return outer.read()
示例11: createhtmlmail
def createhtmlmail(html, text, from_addr, to_addrs, subject):
"""Create a mime-message that will render HTML in popular
MUAs, text in better ones"""
import MimeWriter
import mimetools
import cStringIO
out = cStringIO.StringIO() # output buffer for our message
htmlin = cStringIO.StringIO(html)
txtin = cStringIO.StringIO(text)
writer = MimeWriter.MimeWriter(out)
writer.addheader("From", from_addr)
writer.addheader("To", ', '.join(to_addrs))
#
# set up some basic headers... we put subject here
# because smtplib.sendmail expects it to be in the
# message body
#
writer.addheader("Subject", subject)
writer.addheader("MIME-Version", "1.0")
#
# start the multipart section of the message
# multipart/alternative seems to work better
# on some MUAs than multipart/mixed
#
writer.startmultipartbody("alternative")
writer.flushheaders()
#
# the plain text section
#
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
pout = subpart.startbody("text/plain", [("charset", 'us-ascii')])
mimetools.encode(txtin, pout, 'quoted-printable')
txtin.close()
#
# start the html subpart of the message
#
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
#
# returns us a file-ish object we can write to
#
pout = subpart.startbody("text/html", [("charset", 'us-ascii')])
mimetools.encode(htmlin, pout, 'quoted-printable')
htmlin.close()
#
# Now that we're done, close our writer and
# return the message body
#
writer.lastpart()
msg = out.getvalue()
out.close()
#print msg
return msg
示例12: _send_it
def _send_it(subject, sender, recipients, text, html, tries):
import cStringIO, mimetools, MimeWriter
out = cStringIO.StringIO()
htmlin = cStringIO.StringIO(html)
txtin = cStringIO.StringIO(text)
writer = MimeWriter.MimeWriter(out)
# headers
writer.addheader("From", sender)
writer.addheader("To", ','.join(recipients))
writer.addheader("Subject", subject)
writer.addheader("X-Mailer", "SmailiMail [version 1.0]")
writer.addheader("MIME-Version", "1.0")
writer.startmultipartbody("alternative")
writer.flushheaders()
# text
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
pout = subpart.startbody("text/plain", [("charset", 'UTF-8')])
mimetools.encode(txtin, pout, 'quoted-printable')
txtin.close()
# html
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
pout = subpart.startbody("text/html", [("charset", 'UTF-8')])
mimetools.encode(htmlin, pout, 'quoted-printable')
htmlin.close()
# to string
writer.lastpart()
msg = out.getvalue()
out.close()
class PostFixThread(Thread):
def __init__(self):
Thread.__init__(self)
self.result = False
def run(self):
self.result = _call_postfix(sender, recipients, msg)
thr = PostFixThread()
thr.start()
thr.join(MAIL_TIMEOUT)
if thr.isAlive():
Thread._Thread__stop(thr)
thr.result = False
if not thr.result and tries < 5:
_send_it(subject, sender, recipients, text, html, tries + 1)
示例13: createhtmlmail
def createhtmlmail(fromAddress, toAddresses, subject, html, text=None,bcc=None):
"Create a mime-message that will render as HTML or text, as appropriate"
if text is None:
# Produce an approximate textual rendering of the HTML string,
# unless you have been given a better version as an argument
import htmllib, formatter
textout = cStringIO.StringIO()
formtext = formatter.AbstractFormatter(formatter.DumbWriter(textout))
parser = htmllib.HTMLParser(formtext)
parser.feed(html)
parser.close()
text = textout.getvalue()
del textout, formtext, parser
out = cStringIO.StringIO() # output buffer for our message
htmlin = cStringIO.StringIO(html)
txtin = cStringIO.StringIO(text)
writer = MimeWriter.MimeWriter(out)
# Set up some basic headers. Place subject here
# because smtplib.sendmail expects it to be in the
# message body, as relevant RFCs prescribe.
writer.addheader('From', fromAddress)
writer.addheader('To', ', '.join(toAddresses))
if bcc is not None:
writer.addheader('Bcc', ', '.join(bcc))
writer.addheader("Subject", subject)
writer.addheader("MIME-Version", "1.0")
# Start the multipart section of the message.
# Multipart/alternative seems to work better
# on some MUAs than multipart/mixed.
writer.startmultipartbody("alternative")
writer.flushheaders()
# the plain-text section: just copied through, assuming iso-8859-1
subpart = writer.nextpart()
pout = subpart.startbody("text/plain", [("charset", 'iso-8859-1')])
pout.write(txtin.read())
txtin.close()
# the HTML subpart of the message: quoted-printable, just in case
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
pout = subpart.startbody("text/html", [("charset", 'us-ascii')])
mimetools.encode(htmlin, pout, 'quoted-printable')
htmlin.close()
# You're done; close your writer and return the message body
writer.lastpart()
msg = out.getvalue()
out.close()
return msg
示例14: test_decodeencode
def test_decodeencode(self):
start = string.ascii_letters + "=" + string.digits + "\n"
for enc in ["7bit", "8bit", "base64", "quoted-printable", "uuencode", "x-uuencode", "uue", "x-uue"]:
i = StringIO.StringIO(start)
o = StringIO.StringIO()
mimetools.encode(i, o, enc)
i = StringIO.StringIO(o.getvalue())
o = StringIO.StringIO()
mimetools.decode(i, o, enc)
self.assertEqual(o.getvalue(), start)
示例15: __init__
def __init__(self, fromEmail, toEmail, subject, email_body):
"""Create a mime-message that will render HTML in popular
MUAs, text in better ones"""
self._from = fromEmail
self._to = toEmail
self._title = subject
self.txt_msg = email_body
self._msg = email_body
out = cStringIO.StringIO() # output buffer for our message
htmlin = cStringIO.StringIO(email_body)
txtin = cStringIO.StringIO(email_body)
writer = MimeWriter.MimeWriter(out)
#
# set up some basic headers... we put subject here
# because smtplib.sendmail expects it to be in the
# message body
#
writer.addheader("From", self._from)
writer.addheader("Subject", self._title)
writer.addheader("MIME-Version", "1.0")
#
# start the multipart section of the message
# multipart/alternative seems to work better
# on some MUAs than multipart/mixed
#
writer.startmultipartbody("alternative")
writer.flushheaders()
#
# the plain text section
#
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
pout = subpart.startbody("text/plain", [("charset", 'us-ascii')])
mimetools.encode(txtin, pout, 'quoted-printable')
txtin.close()
#
# start the html subpart of the message
#
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
#
# returns us a file-ish object we can write to
#
pout = subpart.startbody("text/html", [("charset", 'us-ascii')])
mimetools.encode(htmlin, pout, 'quoted-printable')
htmlin.close()
#
# Now that we're done, close our writer and
# return the message body
#
writer.lastpart()
self._msg = out.getvalue()
out.close()
return