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

S

scrimp

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
 
J

John Roth

scrimp said:
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
 
S

scrimp

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?
 
S

scrimp

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
 
P

Peter Hansen

scrimp said:
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
 
J

John Roth

scrimp said:
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
 
S

scrimp

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top