Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'msg': 0.07; 'coding:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Python3': 0.09; 'from:addr:cheimes.de': 0.16; 'from:addr:lists': 0.16; 'from:name:christian heimes': 0.16; 'message()': 0.16; 'message-id:@dough.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'script?': 0.16; 'smtplib': 0.16; 'subject:non': 0.16; "test'": 0.16; '>>>': 0.18; 'skip:" 40': 0.20; 'import': 0.21; 'faq': 0.22; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:m 30': 0.26; 'skip:# 10': 0.27; 'header:X-Complaints-To:1': 0.28; 'skip:q 20': 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'subject: ?': 0.30; 'web.': 0.30; 'docs': 0.33; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'christian': 0.34; 'wrong': 0.34; 'thanks': 0.34; 'received:org': 0.36; 'but': 0.36; 'subject:with': 0.36; 'test': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'subject:-': 0.40; 'header:Received:5': 0.40; 'results': 0.65 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Christian Heimes Subject: Re: email with a non-ascii charset in Python3 ? Date: Wed, 15 Aug 2012 14:48:40 +0200 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: smtp.semantics.de User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1345034937 news.xs4all.nl 6879 [2001:888:2000:d::a6]:55950 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27092 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