当前位置: 首页>>代码示例>>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;未经允许,请勿转载。