當前位置: 首頁>>代碼示例>>Python>>正文


Python MimeWriter.MimeWriter方法代碼示例

本文整理匯總了Python中MimeWriter.MimeWriter方法的典型用法代碼示例。如果您正苦於以下問題:Python MimeWriter.MimeWriter方法的具體用法?Python MimeWriter.MimeWriter怎麽用?Python MimeWriter.MimeWriter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MimeWriter的用法示例。


在下文中一共展示了MimeWriter.MimeWriter方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: sendmail

# 需要導入模塊: import MimeWriter [as 別名]
# 或者: from MimeWriter import MimeWriter [as 別名]
def sendmail(phoneNumber,data,toaddr):
   smtpConn=smtplib.SMTP(smtp_server)
   #smtpConn.set_debuglevel(1)
   fromaddr='admin@webspherediy.com'
   #msg=("From: %s\r\nTo: %s\r\n\r\n" % (fromaddr,toaddr)) 
   msg=data
    
   msg=StringIO.StringIO()
   writer=MimeWriter.MimeWriter(msg)
   writer.addheader('MIME-Version', '1.0')
   writer.addheader('Subject','reverse phone lookup result for: '+phoneNumber)
   writer.startmultipartbody('mixed')
   part=writer.nextpart()
   body=part.startbody('text/html')
   body.write(data)
   writer.lastpart()
   smtpConn.sendmail(fromaddr,toaddr,msg.getvalue())
   smtpConn.quit() 
開發者ID:ActiveState,項目名稱:code,代碼行數:20,代碼來源:recipe-145126.py

示例2: createhtmlmail

# 需要導入模塊: import MimeWriter [as 別名]
# 或者: from MimeWriter import MimeWriter [as 別名]
def createhtmlmail(subject, text, html, email_from, email_to, email_replyto):
    " Create a mime-message that will render as HTML or text, as appropriate"

    out = cStringIO.StringIO( )              # output buffer for our message
    htmlin = cStringIO.StringIO(html)    # input buffer for the HTML
    txtin = cStringIO.StringIO(text)     # input buffer for the plain text
    writer = MimeWriter.MimeWriter(out)
    # Set up some basic headers. Place subject here because smtplib.sendmail
    # expects it to be in the message, as relevant RFCs prescribe.
    writer.addheader("Subject", subject)
    writer.addheader("To", email_to)
    writer.addheader("MIME-Version", "1.0")
    writer.addheader("From", email_from)
    writer.addheader("Reply-To", email_replyto)
    writer.addheader("Cc", email_replyto)
    writer.addheader("Date", email.Utils.formatdate(localtime=1))
    writer.addheader("Message-ID", email.Utils.make_msgid())

    # 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 = subpart.startbody("text/plain", [("charset", 'utf-8')])
    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")
    subpart.addheader("Content-Transfer-Encoding", "8bit")
    #pout = subpart.startbody("text/html", [("charset", 'us-ascii')])
    pout = subpart.startbody("text/html", [("charset", 'utf-8')])
    #mimetools.encode(htmlin, pout, 'quoted-printable')
    mimetools.encode(htmlin, pout, '8bit')
    htmlin.close( )
    # You're done; close your writer and return the message as a string
    writer.lastpart( )
    msg = out.getvalue( )
    out.close( )
    return msg 
開發者ID:teamtachyon,項目名稱:Quillpad-Server,代碼行數:44,代碼來源:startquill_cherry.py

示例3: createhtmlmail

# 需要導入模塊: import MimeWriter [as 別名]
# 或者: from MimeWriter import MimeWriter [as 別名]
def createhtmlmail(subject, html, text=None):
    """
    Create a mime-message that will render as HTML or text as appropriate.
    If no text is supplied we use htmllib to guess a text rendering. 
    (so html needs to be well formed) 
    
    Adapted from recipe 13.5 from Python Cookbook 2
    """
    import MimeWriter, mimetools, StringIO
    if text is None:
        # produce an approximate text from the HTML input
        import htmllib
        import formatter
        textout = StringIO.StringIO()
        formtext = formatter.AbstractFormatter(formatter.DumbWriter(textout))
        parser = htmllib.HTMLParser(formtext)
        parser.feed(html)
        parser.close()
        text = textout.getvalue()
        del textout, formtext, parser
    out = StringIO.StringIO()       # output buffer for our message
    htmlin = StringIO.StringIO(html)  # input buffer for the HTML
    txtin = StringIO.StringIO(text)   # input buffer for the plain text
    writer = MimeWriter.MimeWriter(out)
    # Set up some basic headers. Place subject here because smtplib.sendmail
    # expects it to be in the message, 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  # XXXX always true ?
    subpart = writer.nextpart()
    pout = subpart.startbody("text/plain", [("charset", 'iso-8859-l')]) 
    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 as a string
    writer.lastpart()
    msg = out.getvalue()
    out.close()
    return msg 
開發者ID:amir-zeldes,項目名稱:rstWeb,代碼行數:50,代碼來源:cgiutils.py


注:本文中的MimeWriter.MimeWriter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。