> I am using the template to build the email content.  I included links
> in it but the email are sent in plain text, not in html.  What is the
> way to go to send html email ?  Eventually, i'd like to add images too.

Hi Rem,

I got this one off the cookbook a while back. You'll have to call it
after render, and it will return a text object suitable for sending.

import cStringIO, MimeWriter, mimetools

def createhtmlmail(subject, html, text=""):
    """Create a mime-message that will render HTML in popular
    MUAs, text in better ones"""

    out = cStringIO.StringIO() # output buffer for our message
    htmlin = cStringIO.StringIO(html)

    writer = MimeWriter.MimeWriter(out)
    writer.addheader("Subject", subject)
    writer.addheader("MIME-Version", "1.0")
    writer.startmultipartbody("alternative")
    writer.flushheaders()

    #
    # the plain text section
    #
    if text:
        txtin = cStringIO.StringIO(text)
        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")
    pout = subpart.startbody("text/html", [("charset", 'us-ascii')])
    mimetools.encode(htmlin, pout, 'quoted-printable')
    htmlin.close()
    writer.lastpart()
    msg = out.getvalue()
    out.close()
    #print msg
    return msg

hth,
-- bjorn


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to