|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Creating message partsHi all,
I may have the wrong end of the stick entirely, but I'll try to be as clear as possible. I'm trying to create a message part that will later be attached to another message. However, if I do E = email.mime.multipart.MIMEMultipart() print E.as_string() Then E is given a "MIME-Version: 1.0" header, which I don't think it should have (the "parent" email message will have that header, of course). I have a feeling, therefore, that I am doing something wrong! Should I not be using the MIMEMultipart() calss for this purpose? And if not, what should I be using? Best wishes, Nicholas _______________________________________________ Email-SIG mailing list Email-SIG@... Your options: http://mail.python.org/mailman/options/email-sig/lists%40nabble.com |
|
|
Re: Creating message partsOn Wed, Sep 24, 2008 at 03:37:53PM +0100, Nicholas Cole wrote:
> E = email.mime.multipart.MIMEMultipart() > print E.as_string() > > Then E is given a "MIME-Version: 1.0" header, which I don't think it > should have (the "parent" email message will have that header, of > course). > > I have a feeling, therefore, that I am doing something wrong! Should > I not be using the MIMEMultipart() calss for this purpose? And if not, > what should I be using? MIMEMultipart is a class for the top-level part (the entire message). For subparts use classes like MIMEText et al. Compare these 3 examples: ----- 1 ----- from email import MIMEText msg = MIMEText.MIMEText("This is a simple message", _charset="latin-1") msg["Subject"] = "Text" print str(msg) ----- /1 ----- ----- 2 ----- from email import MIMENonMultipart msg = MIMENonMultipart.MIMENonMultipart("text", "plain", charset="latin-1") msg["Subject"] = "Simple" msg.set_payload("This is a simple message") print str(msg) ----- /2 ----- ----- 3 ----- from email import MIMEMultipart, MIMEText msg = MIMEMultipart.MIMEMultipart() msg["Subject"] = "Multipart" part = MIMEText.MIMEText("This is a subpart", _charset="latin-1") part["Subject"] = "Subpart" msg.attach(part) print str(msg) ----- /3 ----- Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd@... Programmers don't die, they just GOSUB without RETURN. _______________________________________________ Email-SIG mailing list Email-SIG@... Your options: http://mail.python.org/mailman/options/email-sig/lists%40nabble.com |
|
|
Re: Creating message partsNicholas Cole wrote:
> >I'm trying to create a message part that will later be attached to >another message. However, if I do > >E = email.mime.multipart.MIMEMultipart() >print E.as_string() > >Then E is given a "MIME-Version: 1.0" header, which I don't think it >should have (the "parent" email message will have that header, of >course). > >I have a feeling, therefore, that I am doing something wrong! Should >I not be using the MIMEMultipart() calss for this purpose? And if not, >what should I be using? See <http://docs.python.org/lib/module-email.mime.text.html>. You should use classes like email.mime.application.MIMEApplication, email.mime.image.MIMEImage, email.mime.text.MIMEText, etc. to create the various message parts and then append them to the payload of the parent message. -- Mark Sapiro <mark@...> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan _______________________________________________ Email-SIG mailing list Email-SIG@... Your options: http://mail.python.org/mailman/options/email-sig/lists%40nabble.com |
|
|
Re: Creating message partsOn Wed, Sep 24, 2008 at 4:06 PM, Oleg Broytmann <phd@...> wrote:
> On Wed, Sep 24, 2008 at 03:37:53PM +0100, Nicholas Cole wrote: >> E = email.mime.multipart.MIMEMultipart() >> print E.as_string() >> >> Then E is given a "MIME-Version: 1.0" header, which I don't think it >> should have (the "parent" email message will have that header, of >> course). >> >> I have a feeling, therefore, that I am doing something wrong! Should >> I not be using the MIMEMultipart() calss for this purpose? And if not, >> what should I be using? > > MIMEMultipart is a class for the top-level part (the entire message). > For subparts use classes like MIMEText et al. Compare these 3 examples: > > ----- 3 ----- > from email import MIMEMultipart, MIMEText > msg = MIMEMultipart.MIMEMultipart() > msg["Subject"] = "Multipart" > > part = MIMEText.MIMEText("This is a subpart", _charset="latin-1") > part["Subject"] = "Subpart" > > msg.attach(part) > print str(msg) > ----- /3 ----- > > Oleg. Dear Oleg, Thanks for the examples - things are looking clearer. However, in version 3, on my system the subpart is still given a MIME-Version header. Is this not incorrect? Also, according to the documentation "A MIME-Version: header will also be added" to the MIMEMultipart class, even though it actually seems to be added by the MIMEBase class, and therefore to all subclasses. Best wishes, Nicholas _______________________________________________ Email-SIG mailing list Email-SIG@... Your options: http://mail.python.org/mailman/options/email-sig/lists%40nabble.com |
| Free embeddable forum powered by Nabble | Forum Help |