On Tue, May 17, 2011 at 1:02 PM, John Crawford <cycl...@speakeasy.net>wrote:

> Actually, upon looking more at the output, it has *both* "utf-8" and
> "us-ascii" as the charset.


Actually, it doesn't. It only has utf-8. The first nine lines of your pasted
output are the actual email headers. Following the blank line is the email
body, which begins with three lines that *look* like headers, but are
actually just part of the message, and any email client would just render
them as text at the top of the message.

(In addition to the blank line, this is alse evidenced by the fact that the
'=' in 'charset='us-ascii'" was escaped as '=3D', as is normal for
quoted-printable-encoded text)


> I'm not sure if this is the result of code
> changes I've made, or I just missed it the first time around - but my
> Django email output now looks like this:
>
> ---------- MESSAGE FOLLOWS ----------
> Content-Type: text/plain; charset="utf-8"
> MIME-Version: 1.0
> Content-Transfer-Encoding: quoted-printable
> Subject: some_subject
> From: m...@test.com
> To: m...@test.com
> Date: Tue, 17 May 2011 19:58:16 -0000
> Message-ID: <20110517195816.16624.1004@CRAY>
> X-Peer: 127.0.0.1
>
> Content-Type: text/us-ascii; charset=3D"us-ascii"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
>
> this is a test of a really long line that has more words that could
> possibl=
> y fit in a single column of text.
> ------------ END MESSAGE ------------
>
> So although I'm creating a MIMEText object with a plain, "us-ascii"
> string - somewhere, Django is sending a charset of "utf-8". At least
> if I read this correctly.
>
> So does anyone know how to tell Django to *not* send "utf-8"? Thanks.
>

What are you *actually* doing to send this email? It sounds like you are
creating some kind of object and passing that as the body to send_mail,
while send_mail is expecting text, and is just coercing your object into a
string and using that as the message body.

It is definitely possible to tell Django not to use UTF-8 encoding, but you
won't be able to use the send_mail shortcut to do it. You will have to use
an EmailMessage object directly[1]. You should be able to instantiate an
EmailMessage, set the headers yourself, and call send() on it.

(Also, 'text/us-ascii' is not a registered MIME type; you probably want to
say something like 'text/plain; charset=us-ascii')


[1]
http://docs.djangoproject.com/en/1.3/topics/email/#the-emailmessage-class


-- 
Regards,
Ian Clelland
<clell...@gmail.com>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to