module email

S

Sergey Dorofeev

Hello.

Why does not work?

--------------
import email.message
import smtplib
import time

m=email.message.Message()
m.set_type("multipart/mixed")
m["From"]="Sergey Dorofeev <[email protected]>"
m["To"]="Sergey Dorofeev <[email protected]>"
m["Date"]=time.asctime()
m["Subject"]="test"


p1=email.message.Message()
p1.set_payload("message text", "us-ascii")
m.attach(p1)

p2=email.message.Message()
p2.set_payload("message text 2", "us-ascii")
m.attach(p2)

del p1,p2

print m.as_string()
print "*"*50


x=email.message.Message()
x.set_type("multipart/mixed")
x["From"]="Sergey Dorofeev <[email protected]>"
x["To"]="Sergey Dorofeev <[email protected]>"
x["Date"]=time.asctime()
x["Subject"]="test"

p1=email.message.Message()
p1.set_payload("message text !", "us-ascii")
print p1
x.attach(p1)


p2=email.message.Message()
p2.set_type("message/rfc822")
p2.set_payload(m)
print p2
x.attach(p2)


print "*"*50
print x.as_string()
 
S

Sergey Dorofeev

Rob Wolfe said:
Payload is a _list_ of Message objects (is_multipart() == True)
or a _string_ object (is_multipart() == False) but never just Message
object.

1. If I give m.as_string() into set_payload, result is the same.
2. I don't understand, how message/rfc822 section can accept a list of two
or more messages. Can you explain?
 
R

Rob Wolfe

Sergey said:
1. If I give m.as_string() into set_payload, result is the same.

The payload of a message/rfc822 is treated like a sequence
of length 1. So that works:
p2.set_payload([m])
2. I don't understand, how message/rfc822 section can accept a list of two
or more messages. Can you explain?

That's another question.
I don't understand either, why the payload for message/rfc822 has to be
a list of length 1 and not a Message object itself.
This assumption looks strange to me, too, but I can live with that. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top