Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 20th, 2003, 03:52 PM
Swifty Swifty is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 Swifty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Swifty
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.

Reply With Quote
  #2  
Old August 20th, 2003, 06:35 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #3  
Old August 20th, 2003, 11:38 PM
Swifty Swifty is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 Swifty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Swifty
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.

Reply With Quote
  #4  
Old August 21st, 2003, 08:36 AM
Swifty Swifty is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 Swifty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Swifty
I'm getting an error saying

Quote:
SyntaxError: invalid syntax
File "C:\Python22\mailtest.py", line 48
For data in msg.walk():
&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; ^


Do I have to import something I'm not?

Reply With Quote
  #5  
Old August 21st, 2003, 09:36 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Easy way to read .tif attachments from email?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap