473,405 Members | 2,338 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,405 software developers and data experts.

I got the mail portion working [python]

Thanks for the help in breaking the problem down into manageable pieces

This is the code snippet I ended up using: (I'm decoding excel formatted
files)
the file is an email i created with pine that has an excel file in it and
also a csv file in it, both as MIME attachments. I'm only keeping the
excel data, but fwiw I also found 3 other MIME types in the email:

~/mymail/test] python test.py
from[ Jerome plugh <plugh@hg***@sparks.not> ]
reply to[ Jerome plugh <plugh@hg***@sparks.not> ]
Id[ None ]
multipart[<bound method Message.is_multipart of <email.Message.Message
instance at 0x8169554>>]
partition type[multipart/mixed]
Partition #[ 1 ]
partition Name[ None ]
partition type[text/plain]
Partition #[ 2 ]
partition Name[ None ]
partition type[application/vnd.ms-excel]
Partition #[ 3 ]
partition Name[sample.xls ]
partition type[text/tab-separated-values]
Partition #[ 4 ]
partition Name[ sample.tsv ]
total part count 4
-----

payload = {}
text = open('/tmp/test/it').read()
message = email.message_from_string(text)
hdr = dict(message._headers)

addressFrom = hdr["From"]
addressReply = hdr.get("Reply-To", addressFrom)
messageId = hdr.get("Message-Id")

print "\tfrom[", addressFrom, "]\n\treply to[", addressReply,
"]\n\tId[", messageId, "]"

print "multipart[%s]" % message.is_multipart

count = 0

for partition in message.walk():

pType = partition.get_type()
print "partition type[%s]" % pType
count += 1
print "\tPartition #[", count, "]"
fName = partition.get_filename()
print "\t\tpartition Name[", fName , "]"

if pType == "application/vnd.ms-excel":
part = partition.get_payload(decode=1)

print "\t\tpart Info[", part, "]"

payload[fName] = part

print "total part count", count

David
-------
Tracfone: http://cellphone.duneram.com/index.html
Cam: http://www.duneram.com/cam/index.html
Tax: http://www.duneram.com/index.html

__________________________________________________ _______________
Looking to buy a house? Get informed with the Home Buying Guide from MSN
House & Home. http://coldwellbanker.msn.com/
Jul 18 '05 #1
0 1325

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

Similar topics

7
by: PeterR | last post by:
I've spent weeks trying to write a function that is simple to use for sending emails with attachments, but I my programming skills are not that advanced. I've noticed a few postings in these...
2
by: knoak | last post by:
Hi there, I've found a script at these great Google fora. a script to send emails with attachments. The script is below this message, name etc. aren't mine, but from the original post. My...
9
by: Leo Breebaart | last post by:
I am writing a utility in Python and I'd like to add a command-line option "--mailto <address>" that will cause an e-mail summary to be sent to <address> when the utility finishes running. My...
10
by: gn | last post by:
I'm working on someone else's application. It sends e-mail by code. Before the e-mail address he put smtp like so: ; What does the smtp mean?
15
by: Anand Ganesh | last post by:
HI All, I have an Image. I want to clip a portion of it and copy to another image. How to do this? I know the bounding rectangle to clip. Any suggestions please. Thanks for your time and...
4
by: lesperancer | last post by:
I have 3 tables (office97) tblQuote quoteNbr tblDetails ( quote : 1 <-> M: quoteDetails) quoteNbr detailLine product value
25
by: abhinav | last post by:
Hello guys, I am a novice in python.I have to implement a full fledged mail server ..But i am not able to choose the language.Should i go for C(socket API) or python for this project? What are the...
1
by: William Connery | last post by:
Hi, I have a small python program with e-mail capabilities that I have pieced together from code snippets found on the internet. The program uses the smtplib module to successfully send an...
5
by: sui | last post by:
this is my code import sys, os, glob, datetime, time import smtplib ## Parameters for SMTP session port=587 SMTPserver= 'smtp.gmail.com' SMTPuser= '...@gmail.com' pw= 'fill in here'...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.