473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

module email

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 <se****@prodo.ru>"
m["To"]="Sergey Dorofeev <se****@prodo.ru>"
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 <se****@prodo.ru>"
x["To"]="Sergey Dorofeev <se****@prodo.ru>"
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()

--------------

I'm using Python 2.5
Jan 24 '07 #1
4 1869
At Wednesday 24/1/2007 13:02, Sergey Dorofeev wrote:
>Why does not work?
Some details please?
--
Gabriel Genellina
Softlab SRL


__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Jan 24 '07 #2
"Sergey Dorofeev" <se****@fidoman.ruwrites:
Hello.

Why does not work?
[...]
m=email.message.Message()
[...]
p2=email.message.Message()
p2.set_type("message/rfc822")
p2.set_payload(m)
Payload is a _list_ of Message objects (is_multipart() == True)
or a _string_ object (is_multipart() == False) but never just Message object.

http://docs.python.org/lib/module-email.message.html

--
HTH,
Rob
Jan 24 '07 #3

"Rob Wolfe" <rw@smsnet.plwrote in message news:87************@smsnet.pl...
>p2=email.message.Message()
p2.set_type("message/rfc822")
p2.set_payload(m)

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?
Jan 25 '07 #4

Sergey Dorofeev wrote:
"Rob Wolfe" <rw@smsnet.plwrote in message news:87************@smsnet.pl...
p2=email.message.Message()
p2.set_type("message/rfc822")
p2.set_payload(m)
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.
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. :)

--
Regards,
Rob

Jan 25 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: N.K | last post by:
Hi , Python's existing cookie module doesnt supports new cookie headers SetCookie2 , How to submit a patch for that ? I tried emailing person who owns that module.But no response. Thanks,...
0
by: praba kar | last post by:
Dear All, I have doubt regarding mail sending smtplib module. The below code is I used to send a mail. ########################################## import email.Message import email.Utils...
25
by: Xah Lee | last post by:
Python Doc Problem Example: gzip Xah Lee, 20050831 Today i need to use Python to compress/decompress gzip files. Since i've read the official Python tutorial 8 months ago, have spent 30...
5
by: Barbara Lindsey | last post by:
If this is the wrong list, let me know... I am trying to install the Pg DBD module for Perl DBI and am having a problem. It keeps coming up asking if I read the README file, which i have several...
30
by: Franck PEREZ | last post by:
Hello, I'm developing a small XML marshaller and I'm facing an annoying issue. Here's some sample code: ########### My test application ############ class Foo(object): #The class I'd like to...
3
by: Erik Johnson | last post by:
THE GOAL: I need to send an email with a simple ASCII text body and an attached HTML file. I have scripts that send basic emails via the smtplib module that don't have any attachements and that...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
5
by: Jeff Schwab | last post by:
Q1: When a module is imported, is there any way for the module to determine the name of the client code's module? Q2: My understanding is that the code in a module is executed only on the first...
4
by: rkmr.em | last post by:
Hi I have a function data, that I need to import from a file data, in the directory data If I do this from python interactive shell (linux fedora core 8) from dir /home/mark it works fine: ...
6
by: dudeja.rajat | last post by:
Hi, I found on the net that there is something called module initialization. Unfortunately, there is not much information for this. However, small the information I found module initialization...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.