470,638 Members | 1,510 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,638 developers. It's quick & easy.

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

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

Jul 19 '05 #1
6 2524
"scrimp" <sc*******@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr 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


Jul 19 '05 #2
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?

Jul 19 '05 #3
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

Jul 19 '05 #4
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
Jul 19 '05 #5

"scrimp" <sc*******@yahoo.com> wrote in message
news:11*********************@g43g2000cwa.googlegro 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


Jul 19 '05 #6
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

Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by LutherRevisited | last post: by
5 posts views Thread by paii, Ron | last post: by
1 post views Thread by nabil m | last post: by
1 post views Thread by Jules Mitland | last post: by
6 posts views Thread by c_shah | last post: by
1 post views Thread by Korara | last post: by
???
1 post views Thread by Stoney L | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.