473,757 Members | 10,736 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

module email

Hello.

Why does not work?

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

m=email.message .Message()
m.set_type("mul tipart/mixed")
m["From"]="Sergey Dorofeev <se****@prodo.r u>"
m["To"]="Sergey Dorofeev <se****@prodo.r u>"
m["Date"]=time.asctime()
m["Subject"]="test"
p1=email.messag e.Message()
p1.set_payload( "message text", "us-ascii")
m.attach(p1)

p2=email.messag e.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("mul tipart/mixed")
x["From"]="Sergey Dorofeev <se****@prodo.r u>"
x["To"]="Sergey Dorofeev <se****@prodo.r u>"
x["Date"]=time.asctime()
x["Subject"]="test"

p1=email.messag e.Message()
p1.set_payload( "message text !", "us-ascii")
print p1
x.attach(p1)
p2=email.messag e.Message()
p2.set_type("me ssage/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 1879
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.messag e.Message()
p2.set_type("me ssage/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.plwr ote in message news:87******** ****@smsnet.pl. ..
>p2=email.messa ge.Message()
p2.set_type("m essage/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.plwr ote in message news:87******** ****@smsnet.pl. ..
p2=email.messag e.Message()
p2.set_type("me ssage/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
4320
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, Nirmal
0
522
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 import mimetypes import os,string
25
7753
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 minutes with Python 3 times a week since, have 14 years of computing experience, 8 years in mathematical computing and 4 years in unix admin and perl, i have quickly found the official doc: http://python.org/doc/2.4.1/lib/module-gzip.html
5
2110
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 times. The perl Makefile.PL and make seem to run without problems, but the make test fails. I have confirmed that Postgres is running fine. I've been able to create schema and tables and load data. I have re-built Perl 5.8.2, I have installed...
30
2072
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 serialize pass
3
2519
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 seems to work fine. I first looked at the mimetools modules but it says it is depreceated since 2.3, so I started trying to use the email module. Here is a script that basically follows the second example given in section 7.1.13 of the Python...
21
34435
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 obvious of which is the sharing of files. For example, you upload images to a server to share them with other people over the Internet. Perl comes ready equipped for uploading files via the CGI.pm module, which has long been a core module and allows users...
5
1576
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 import of that module. Is there any way to have a hook invoked on subsequent imports, and for that hook (as in Q1) to determine the name of the client module?
4
2182
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: cwd = data os.chdir(cwd) print os.getcwd()
6
2269
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 can be of use to me in my project. I'm currently messing with a problem where I'm keeping my global variables ( or symbols) in a module and the other mdoules in the project acess these global variables.
0
9298
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10072
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.