Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #27092
| From | Christian Heimes <lists@cheimes.de> |
|---|---|
| Subject | Re: email with a non-ascii charset in Python3 ? |
| Date | 2012-08-15 14:48 +0200 |
| References | <a91i9cFlktU4@mid.dfncis.de> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3310.1345034937.4697.python-list@python.org> (permalink) |
Am 15.08.2012 14:16, schrieb Helmut Jarausch:
> Hi,
>
> I'm sorry to ask such a FAQ but still I couldn't find an answer - neither in the docs nor the web.
>
> What's wrong with the following script?
>
> Many thanks for a hint,
> Helmut.
>
> #!/usr/bin/python3
> #_*_ coding: latin1 _*_
>
> import smtplib
> from email.message import Message
> import datetime
>
> msg= Message()
> msg.set_charset('latin-1')
> msg['Subject'] = "*** Email Test ***"
> msg['From'] = "Email_Tester@numa-sv.igpm.rwth-aachen.de"
> msg['To'] = "jarausch@igpm.rwth-aachen.de"
> msg['Date'] = datetime.datetime.utcnow().strftime('%m/%d/%Y %I:%M:%S %p')
>
> server= smtplib.SMTP("igpm.igpm.rwth-aachen.de")
> msg.set_payload("Gedanken über einen Test","iso-8859-1")
You mustn't combine set_charset() with set_payload() with a charset.
That results into invalid output:
>>> msg = Message()
>>> msg.set_payload("Gedanken über einen Test", "iso-8859-1")
>>> msg.as_string()
'MIME-Version: 1.0\nContent-Type: text/plain;
charset="iso-8859-1"\nContent-Transfer-Encoding:
quoted-printable\n\nGedanken =FCber einen Test'
>>> msg2 = Message()
>>> msg2.set_charset("iso-8859-1")
>>> msg2.set_payload("Gedanken über einen Test", "iso-8859-1")
>>> msg2.as_string()
'MIME-Version: 1.0\nContent-Type: text/plain;
charset="iso-8859-1"\nContent-Transfer-Encoding:
quoted-printable\n\nGedanken über einen Test'
Christian
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
email with a non-ascii charset in Python3 ? Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2012-08-15 12:16 +0000
Re: email with a non-ascii charset in Python3 ? Christian Heimes <lists@cheimes.de> - 2012-08-15 14:48 +0200
Re: email with a non-ascii charset in Python3 ? Helmut Jarausch <jarausch@skynet.be> - 2012-08-15 14:04 +0000
Re: email with a non-ascii charset in Python3 ? MRAB <python@mrabarnett.plus.com> - 2012-08-15 17:57 +0100
Re: email with a non-ascii charset in Python3 ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-15 23:54 +0000
Re: email with a non-ascii charset in Python3 ? Ben Finney <ben+python@benfinney.id.au> - 2012-08-16 14:38 +1000
csiph-web