Forums Neueste Beiträge
 

Probleme mit email: MIMEText

16/09/2008 - 20:43 von Florian Lindner | Report spam
Hallo,

ich will aus einer bestehden Email ein MIMEText Objekt erstellen:




text = """Return-Path: <webmaster@xgm.de>






... X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on
... osiris.centershock.net
... X-Spam-Level:
... X-Spam-Status: No, score=-2.6 required=9.0
testsºYES_00,NO_RELAYS
... autolearn=ham version=3.2.3
... X-Original-To: florian.lindner@xgm.de
... Delivered-To: flindner@osiris.centershock.net
... Received: by osiris.centershock.net (Postfix, from userid 1001)
... id F20922018752; Sat, 13 Sep 2008 09:20:37 +0200 (CEST)
... To: "=?UTF-8?B?Rmxvcmlhbg==?=" <florian.lindner@xgm.de>
... Subject: =?UTF-8?B?TmV1ZSBQcml2YXRlIE5hY2hyaWNodCBlcmhhbHRlbg==?... From: <webmaster@xgm.de>
... Reply-To: <webmaster@xgm.de>
... Sender: <webmaster@xgm.de>
... MIME-Version: 1.0
... Message-ID: <4ac38f9e026c01a721b64c7c644a1b84@xgm.de>
... Date: Sat, 13 Sep 2008 08:45:36 +0200
... Content-Type: text/plain; charset=UTF-8
... Content-Transfer-Encoding: 8bit
... X-Priority: 3
... X-MSMail-Priority: Normal
... X-Mailer: PhpBB3
... X-MimeOLE: phpBB3
... X-phpBB-Origin: phpbb://xgm.de/garching2
...
... Hallo Florian,
... """




from email.mime.text import MIMEText
msg = MIMEText(text)







So weit so gut, aber,




msg["From"]
msg["To"]







Er scheint text zu ignorieren. print msg druckt allerdings den text.

Was stimmt da nicht?

Danke,

Florian
 

Lesen sie die antworten

#1 Marc BlackJack Rintsch
16/09/2008 - 21:19 | Warnen spam
On Tue, 16 Sep 2008 11:43:44 -0700, Florian Lindner wrote:

ich will aus einer bestehden Email ein MIMEText Objekt erstellen:

text = """Return-Path:






... X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on ...
osiris.centershock.net
... X-Spam-Level:
... X-Spam-Status: No, score=-2.6 required=9.0 testsºYES_00,NO_RELAYS
... autolearn=ham version=3.2.3
... X-Original-To: ... Delivered-To:
... Received: by osiris.centershock.net
(Postfix, from userid 1001) ... id F20922018752; Sat, 13 Sep 2008
09:20:37 +0200 (CEST) ... To: "=?UTF-8?B?Rmxvcmlhbg==?="
... Subject:

... Reply-To:
... Sender:
... MIME-Version: 1.0
... Message-ID: ... Date: Sat,
13 Sep 2008 08:45:36 +0200 ... Content-Type: text/plain; charset=UTF-8
... Content-Transfer-Encoding: 8bit
... X-Priority: 3
... X-MSMail-Priority: Normal
... X-Mailer: PhpBB3
... X-MimeOLE: phpBB3
... X-phpBB-Origin: phpbb://xgm.de/garching2 ...
... Hallo Florian,
... """

from email.mime.text import MIMEText
msg = MIMEText(text)







So weit so gut, aber,

msg["From"]
msg["To"]







Er scheint text zu ignorieren. print msg druckt allerdings den text.

Was stimmt da nicht?



Da wird nichts ignoriert. Das ist alles Teil des *Textes*. Das Objekt
repràsentiert den oder einen Textteil einer MIME-Message, nicht eine
komplette MIME-Message. Für komplette Nachrichten ist `MIMEMessage`
zustàndig. Ganz praktisch dafür ist `email.message_from_string()`:

In [483]: msg = email.message_from_string(text)

In [484]: msg['From']
Out[484]: ''

Ciao,
Marc 'BlackJack' Rintsch

Ähnliche fragen