• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python mimetools.encode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mimetools.encode函数的典型用法代码示例。如果您正苦于以下问题:Python encode函数的具体用法?Python encode怎么用?Python encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了encode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:mspangler,项目名称:birdpiss-nzb,代码行数:34,代码来源:notifier.py


示例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
开发者ID:affinitic,项目名称:cenforsoc.skin,代码行数:30,代码来源:mailer.py


示例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]
开发者ID:sipolyashhivangi,项目名称:helloworld,代码行数:25,代码来源:mimeMail.py


示例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
开发者ID:praxis330,项目名称:w4mp-alerts,代码行数:30,代码来源:send_email.py


示例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)
开发者ID:OpenDMM,项目名称:enigma2,代码行数:33,代码来源:plugin.py


示例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
开发者ID:cguagliano,项目名称:communitymodules,代码行数:32,代码来源:mail.py


示例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
开发者ID:srathbun,项目名称:python-scripts,代码行数:34,代码来源:emailTraceback.py


示例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
开发者ID:AnonyHa,项目名称:donkeyji,代码行数:30,代码来源:sendmsg.py


示例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()
开发者ID:jaymccrey,项目名称:CSC344,代码行数:34,代码来源:projmail.py


示例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()
开发者ID:OS2World,项目名称:APP-SERVER-Zope,代码行数:60,代码来源:MIMETag.py


示例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
开发者ID:kmillar,项目名称:BBS,代码行数:58,代码来源:email.py


示例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)
开发者ID:smaili,项目名称:ripto,代码行数:57,代码来源:mailer.py


示例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
开发者ID:timparkin,项目名称:into-the-light,代码行数:56,代码来源:mailutil.py


示例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)
开发者ID:Jarga,项目名称:IBM-Innovate-2012,代码行数:10,代码来源:test_mimetools.py


示例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
开发者ID:c24b,项目名称:reporting,代码行数:55,代码来源:send_email2.py


示例16: 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)
开发者ID:B-Rich,项目名称:breve,代码行数:11,代码来源:test_mimetools.py


示例17: sendHtmlMail

def sendHtmlMail(smtpServer, sender, receiver, subject, html, user=None, password=None):
    "Sends an html email (html argument is an HTML string)"
    import MimeWriter
    import mimetools
    import io

    # Produce an approximate textual rendering of the HTML string,
    # unless you have been given a better version as an argument
    import htmllib, formatter
    textout = io.StringIO()
    formtext = formatter.AbstractFormatter(formatter.DumbWriter(textout))
    parser = htmllib.HTMLParser(formtext)
    parser.feed(html)
    parser.close()
    text = textout.getvalue()
    del textout, formtext, parser

    out = io.StringIO() # output buffer for our message
    htmlin = io.StringIO(html)
    txtin = io.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("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()
    smtpServer._sendMail(smtpServer,sender, receiver, msg, user=user, password=password)
开发者ID:AndyKovv,项目名称:hostel,代码行数:53,代码来源:sendmail.py


示例18: write_query_request

def write_query_request(writer, query_name, query, service_url, api_key):
	params = {
		'query': json.dumps(query),
		'key': api_key
	}
	txtin = StringIO.StringIO("GET " + service_url + '?' + urllib.urlencode(params) + "\n")
	subpart = writer.nextpart()
	subpart.addheader("Content-Transfer-Encoding", "binary")
	subpart.addheader("Content-ID", "<" + query_name + ">")
	pout = subpart.startbody("application/http")
	mimetools.encode(txtin, pout, '8bit')
	txtin.close()
开发者ID:tfmorris,项目名称:freebase-python-samples,代码行数:12,代码来源:mqlread-batch.py


示例19: send_attachment

	def send_attachment(self, mail_from = '', to = '', subject = '', attach_list = None, html_file = ''):
                """
                        Send email  with attachment
                """
	
		message = StringIO.StringIO()
                writer = MimeWriter.MimeWriter(message)

                writer = MimeWriter.MimeWriter(message)

                writer.addheader('To', to)
                writer.addheader('From', mail_from)
                writer.addheader('Subject', subject)
                writer.addheader('MIME-Version', '1.0')

                writer.startmultipartbody('mixed')
                writer.flushheaders()

                # start with a text/plain part
                part = writer.nextpart()
                body = part.startbody('text/plain', [("charset", 'utf-8')])
                part.flushheaders()

                for text in open(html_file):
                        body.write(text.encode('utf-8'))

                	# now add the attachments
		if attach_list is not None:
               	 	for attachment in attach_list:
                		for attach in attachment.split(","):
                        		filename = os.path.basename(attach)

                                	ctype, encoding = mimetypes.guess_type(attach)
                                	if ctype is None:
                                		ctype = 'application/octet-stream'
                                        	encoding = 'base64'
                                	elif ctype == 'text/plain':
                                		encoding = 'quoted-printable'
                                	else:
                                        	encoding = 'base64'

                                	part = writer.nextpart()
                                	part.addheader('Content-Transfer-Encoding', encoding)

                               	 	body = part.startbody("%s; name=%s" % (ctype, filename))
                                	mimetools.encode(open(attach, 'rb'), body, encoding)

                writer.lastpart()
                msg = message.getvalue()

                return msg
开发者ID:Debug-Orz,项目名称:sees,代码行数:51,代码来源:smtp.py


示例20: send_mail

	def send_mail():
		print "[CrashlogAutoSubmit] - send_mail"
		if len(crashLogFilelist):
			for crashlog in crashLogFilelist:
				filename = str(os.path.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)
开发者ID:st7TEAM,项目名称:dreambox,代码行数:14,代码来源:plugin.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mimetools.Message类代码示例发布时间:2022-05-27
下一篇:
Python mimetools.decode函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap