Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > saving .zip or .txt email attachments instead of deleting them

Reply
Thread Tools

saving .zip or .txt email attachments instead of deleting them

 
 
scrimp
Guest
Posts: n/a
 
      06-02-2005
How would I go about retriving an email message and stripping out the
attachment into a file. I have seen examples where they would read in
the file and delete the attachment and replace it with text saying that
the attachment was removed.

For testing purposes Im using a pop3 server to receive messages from. I
can log into the pop3 server get all the messages and print them to the
screen or to a file.

I have another script that I got from ActiveSource that deletes the
attachment. This is where I will need to save the attachment instead of
deleting it. Any help is appreciated thanks!

--Barry

 
Reply With Quote
 
 
 
 
John Roth
Guest
Posts: n/a
 
      06-02-2005
"scrimp" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> How would I go about retriving an email message and stripping out the
> attachment into a file. I have seen examples where they would read in
> the file and delete the attachment and replace it with text saying that
> the attachment was removed.
>
> For testing purposes Im using a pop3 server to receive messages from. I
> can log into the pop3 server get all the messages and print them to the
> screen or to a file.
>
> I have another script that I got from ActiveSource that deletes the
> attachment. This is where I will need to save the attachment instead of
> deleting it. Any help is appreciated thanks!


Look at the documentation for the email module in the Python Library
Reference. The final example shows how to read an email and save
all the parts into a directory. It's almost usable as is; I had to tweak
it just a little for what I wanted it to do.

John Roth

>
> --Barry
>


 
Reply With Quote
 
 
 
 
scrimp
Guest
Posts: n/a
 
      06-02-2005
Im using the winpython IDE to run that script for the unpacking the
email. The usage says unpackmail [options] msgfile. I type unpackmail
-d filename and it gives me a syntax error. What modifications did u do
to that module to make it work?

 
Reply With Quote
 
scrimp
Guest
Posts: n/a
 
      06-02-2005
OK i got past that syntax error I think. This is the error I am getting
now....AttributeError: 'NoneType' object has no attribute 'lower' All
Im reading is a text file of the email message with an attachment --zip
file

 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      06-02-2005
scrimp wrote:
> OK i got past that syntax error I think. This is the error I am getting
> now....AttributeError: 'NoneType' object has no attribute 'lower' All
> Im reading is a text file of the email message with an attachment --zip
> file


Always post a *complete* traceback, with the line numbers and all, cut
and pasted from the output window. That way there's no chance we will
misunderstand the error you are getting or have to guess at what's
really happening.

-Peter
 
Reply With Quote
 
John Roth
Guest
Posts: n/a
 
      06-03-2005

"scrimp" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Im using the winpython IDE to run that script for the unpacking the
> email. The usage says unpackmail [options] msgfile. I type unpackmail
> -d filename and it gives me a syntax error. What modifications did u do
> to that module to make it work?


I always run it from the command line. With all due respect to the
authors, there are too many problems with command execution in
PythonWin for me to bother. These aren't precisely bugs, but they
are environmental limitations which make it impractical to use it the
way I usually use it.

And as Peter said, please cut and paste the complete output, including
the command you entered. Thanks.

John Roth
>


 
Reply With Quote
 
scrimp
Guest
Posts: n/a
 
      06-03-2005
Here is the complete traceback..sorry about that though.

I used the run button and entered in "C:\email.txt" for the msgfile
parameter thats used for input

This email.txt file has a zip file attached to it and is all in text,
so hopefully I am working with the correct input file. I used the pop3
example given in the python documentation to pick up a message on the
mail server and read and wrote the information to a file --> email.txt

Traceback (most recent call last):
File
"C:\PYTHON23\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py" ,
line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\My Documents\python scripts\EmailUnpack.py", line 83, in ?
main()
File "C:\My Documents\python scripts\EmailUnpack.py", line 71, in
main
ext = mimetypes.guess_extension(part.get_type())
File "C:\PYTHON23\lib\mimetypes.py", line 178, in guess_extension
extensions = self.guess_all_extensions(type, strict)
File "C:\PYTHON23\lib\mimetypes.py", line 157, in
guess_all_extensions
type = type.lower()
AttributeError: 'NoneType' object has no attribute 'lower'

Again, thanks!

--Barry

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Differentiating file attachments from inline attachments in Exchange Peter Green Python 0 11-05-2009 04:13 PM
mail.Attachments (Multiple Attachments) from Querystring codewarrior ASP .Net 0 05-04-2009 07:19 PM
Getting/Saving email attachments w/ poplib and email modules brettk@gmail.com Python 2 06-22-2005 12:44 PM
Lemme ask again re .email extension as email attachments?? JustMe Computer Support 1 06-15-2005 11:11 PM
attachments unable to read attachments from email bub.mk Computer Support 1 09-29-2004 02:29 AM



Advertisments