|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
Easy way to read .tif attachments from email?
Hi, I'm new to the forum & I'm just learing Python. I apologize in advance if this question has been answered previously, I haven't seen any threads in my searches.
I'm trying to find an easy and straightforward way to extract a .tif (or any other image type, for that matter) from an email attachment and place it in a local directory. Any help will be greatly appreciated. Thanks! -Ryan Last edited by Swifty : August 20th, 2003 at 03:56 PM. |
|
#2
|
||||
|
||||
|
Hi swifty,
This script should do the basics of what you want. You may want to look at the email module in Python's docs for more info.. http://www.python.org/doc/current/lib/module-email.html Code:
#get email and assign it to msg, you need to change email to your email source
msg = email.message_from_file(email)
#Step through the mine headers
For data in msg.walk():
#get a filename from the header and assign it to name
name = data.get_filename()
#if name ends with .tif write the attachment to the appropriate place.
if name.endswith('.tif'):
#create the attachment data.get_payload does the actual extraction. this is then written to a file.
file = open(name, 'w').write(data.get_payload(decode = 1))
Hope this helps, Mark. |
|
#3
|
|||
|
|||
|
Excellent, thanks a million! I couldn't find that Python doc for the life of me either. I'll give it a shot when I go back to work tomorrow.
|
|
#4
|
|||
|
|||
|
I'm getting an error saying
Quote:
Do I have to import something I'm not? |
|
#5
|
||||
|
||||
|
You will need to import the email module but other than that nothing. The error is being caused by 'For', if you change it to 'for' if should work fine.. sorry
, musta hit shift when I was typing it hehe .Take care, Mark. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Easy way to read .tif attachments from email? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|