Work around UnicodeEncodeError when attaching unicode HTML content

See this ticket: https://code.djangoproject.com/ticket/20230

Only occurs on Python < 2.6.6. Since the ticket is marked as wontfix
in Django, it makes sense to fix it here.