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

Discussion in 'Python' started by scrimp, Jun 2, 2005.

  1. scrimp

    scrimp Guest

    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
    scrimp, Jun 2, 2005
    #1
    1. Advertising

  2. scrimp

    John Roth Guest

    "scrimp" <> wrote in message
    news:...
    > 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
    >
    John Roth, Jun 2, 2005
    #2
    1. Advertising

  3. scrimp

    scrimp Guest

    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?
    scrimp, Jun 2, 2005
    #3
  4. scrimp

    scrimp Guest

    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
    scrimp, Jun 2, 2005
    #4
  5. scrimp

    Peter Hansen Guest

    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
    Peter Hansen, Jun 2, 2005
    #5
  6. scrimp

    John Roth Guest

    "scrimp" <> wrote in message
    news:...
    > 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
    >
    John Roth, Jun 3, 2005
    #6
  7. scrimp

    scrimp Guest

    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
    scrimp, Jun 3, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    1,093
    Mike Meyer
    Jun 22, 2005
  2. Sameen
    Replies:
    2
    Views:
    423
    Victor Bazarov
    Aug 29, 2005
  3. codewarrior
    Replies:
    0
    Views:
    518
    codewarrior
    May 4, 2009
  4. Peter Green
    Replies:
    0
    Views:
    629
    Peter Green
    Nov 5, 2009
  5. Jochen Brenzlinger
    Replies:
    7
    Views:
    5,471
    Roedy Green
    Sep 15, 2011
Loading...

Share This Page